- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ 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; } //Identify this question var thisQuestion = $('#question{QID}'); var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent(); // Fill the arrays with the subquestion codes var arrayA=[1,2,3]; var arrayB=[4,5,6]; var arrayC=[7,8,9]; shuffleArray(arrayA); shuffleArray(arrayB); shuffleArray(arrayC); var arrayZ=[arrayA,arrayB,arrayC]; shuffleArray(arrayZ); var answerCodes = arrayZ.join(",").split(','); // Loop through the answer codes $.each(answerCodes, function(i, val) { // Move the answer item $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion)); }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the sub-heading text strings var subHeading = '<th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th>'; var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length; // Insert the new rows $('tr.answers-list:eq(1)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>'); $('tr.answers-list:eq(2)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>'); $('tr.answers-list:eq(3)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>'); // For all subquestions - or however you want // Fix up the row classes var rowClass = 1; $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('sub-header-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script>
<style type="text/css"> .sub-header-row { color: maroon; font-weight:bold; text-align: center; } </style>
Please Log in to join the conversation.