- Posts: 10260
- Thank you received: 3648
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready',function(){ // Identify this question var thisQuestion = $('#question{QID}'); var thisTable = $('table.subquestion-list', thisQuestion); // Randomize the rows var rowsArr = []; $('tr.answers-list', thisTable).each(function(i){ $(this).attr('data-index', i); rowsArr.push(i); }); shuffleArray(rowsArr); $(rowsArr).each(function(i){ $('tbody:eq(0)', thisTable).append($('tr[data-index="'+this+'"]', thisTable)); }); // Fix up the row classes var rowClass = 1; $('tr.answers-list', thisTable).removeClass('ls-even ls-odd').each(function(i) { if(i%2 == 0) { $(this).addClass('ls-even'); } else { $(this).addClass('ls-odd'); } }); }); function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } </script>
I think Yves' point is about array questions where you have both sub-questions and answers randomized in 4.x.