I want to order a array based on the current week day.
I know that limesurvey allows to order randomly a question and there are some workarounds for this too. But my order is specify and not random.
If someone answers on a thursday, that should be the first item from the list and go down (wednesday, tuesday, monday...) and this should always change depending on the day of the week the survey is taken.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. -
Professional support
-
Plugins, theme and development
. I don't answer to private message.
I was thinking about this and while there is no way to order this out of the box, but as a workaround you could create 7 questions for this, with the respective order. Now you would just need to figure out how to find out which day of the week it is to show one of these questions and hide the others. Later you will have join these for analysis. Is probably doable via Javascript.
Help us to help you!
Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
Assuming you set up the array sub-questions ordered Sunday-Saturday, adding this script to the source of the array should do the trick:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Identify the day of the week
var todayDate = new Date();
var weekDay = todayDate.getDay();
// Move the array rows
$('tr.answers-list:lt('+weekDay+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
});
</script>
Oops, sorry, I mis-read the order that you want. If you order the sub-questions reversed Saturday, Friday...Monday,Sunday, use this script:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Identify the day of the week
var todayDate = new Date();
var weekDay = todayDate.getDay();
var reverseWeekDay = 6-weekDay
// Move the array rows
$('tr.answers-list:lt('+(reverseWeekDay)+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
});
</script>
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. -
Professional support
-
Plugins, theme and development
. I don't answer to private message.
This should work for normal ordering (Sunday,Monday...Friday,Saturday):
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Identify the day of the week
var todayDate = new Date();
var weekDay = todayDate.getDay();
// Move the array rows
$('table.subquestion-list tr[id^="javatbd"]:lt('+weekDay+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
});
</script>
And this for reverse ordering (Saturday, Friday...Monday,Sunday):
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Identify the day of the week
var todayDate = new Date();
var weekDay = todayDate.getDay();
var reverseWeekDay = 6-weekDay
// Move the array rows
$('table.subquestion-list tr[id^="javatbd"]:lt('+(reverseWeekDay)+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
});
</script>
Cheers,
Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Thank you again tpartner.
I've also used this on a multiple numerical input.
Here's the code for the reverse ordering:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Identify the day of the week
var todayDate = new Date();
var weekDay = todayDate.getDay();
var reverseWeekDay = 6-weekDay
// Move the array rows
$('table.table-multi-num tr[id^="javatbd"]:lt('+(reverseWeekDay)+')', thisQuestion).appendTo($('table.table-multi-num tbody:eq(0)', thisQuestion));
});
</script>
And the code for normal ordering:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var thisQuestion = $('#question{QID}');
// Identify the day of the week
var todayDate = new Date();
var weekDay = todayDate.getDay();
// Move the array rows
$('table.table-multi-num tr[id^="javatbd"]:lt('+(weekDay)+')', thisQuestion).appendTo($('table.table-multi-num tbody:eq(0)', thisQuestion));
});
</script>