Place this in template.js:
Code:
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;
}
Place something like this in the source of a multiple-choice question (adjust the sub-question codes as required):
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// First group of sub-question codes
var sqCodes1 = ['SQ001', 'SQ002', 'SQ003'];
// Second group of sub-question codes
var sqCodes2 = ['SQ004', 'SQ005', 'SQ006'];
// Shuffle the subquestions
shuffleArray(sqCodes1);
shuffleArray(sqCodes2);
// Insert the rows in the shuffled order
$(sqCodes1).each(function(i, val){
$('.subquestions-list', thisQuestion).append($('.question-item[id$="X'+qID+val+'"]', thisQuestion));
});
$(sqCodes2).each(function(i, val){
$('.subquestions-list', thisQuestion).append($('.question-item[id$="X'+qID+val+'"]', thisQuestion));
});
});
</script>
Place something like this in the source of an array question (adjust the sub-question codes as required):
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// First group of sub-question codes
var sqCodes1 = ['SQ001', 'SQ002', 'SQ003'];
// Second group of sub-question codes
var sqCodes2 = ['SQ004', 'SQ005', 'SQ006'];
// Shuffle the subquestions
shuffleArray(sqCodes1);
shuffleArray(sqCodes2);
// Insert the rows in the shuffled order
$(sqCodes1).each(function(i, val){
$('table.subquestions-list', thisQuestion).append($('.answers-list[id$="X'+qID+val+'"]', thisQuestion));
});
$(sqCodes2).each(function(i, val){
$('table.subquestions-list', thisQuestion).append($('.answers-list[id$="X'+qID+val+'"]', thisQuestion));
});
});
</script>
Place something like this in the source of a list-radio question (adjust the answer codes as required):
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Identify this question
var qID = {QID};
var thisQuestion = $('#question'+qID);
// First group of answer codes
var answerCodes1 = ['A1', 'A2', 'A3'];
// Second group of answer codes
var answerCodes2 = ['A4', 'A5', 'A6'];
// Shuffle the subquestions
shuffleArray(answerCodes1);
shuffleArray(answerCodes2);
// Insert the rows in the shuffled order
$(answerCodes1).each(function(i, val){
$('.answers-list', thisQuestion).append($('.answer-item[id$="X'+qID+val+'"]', thisQuestion));
});
$(answerCodes2).each(function(i, val){
$('.answers-list', thisQuestion).append($('.answer-item[id$="X'+qID+val+'"]', thisQuestion));
});
});
</script>
Sample survey attached: