I have a survey where I have 11 products, I need to select 4 to test and then ask questions regarding each of the 4 products selected. If I ask this as a multi-choice, is there any way to pull those back out but in a random order, to be used as text subs in the following parts of the survey?
Unfortunately group randomisation is not possible, as each product runs over many groups, and then needs to be repeated.
Ideally I'd like to have 4 equation questions following the list of products, each with a product as the value, but assigned randomly.
Is this possible? Happy to hear alternative suggestions
1) Place a hidden (via CSS class) multiple-short-text question with 4 sub-questions directly after the multiple-choice.
2) Add this script to the source of the multiple-short-text. It will create a randomized array of checked labels and load the inputs in the multiple-short-text with those values. These can then be used later in the survey.
Code:
<script type="text/javascript" charset="utf-8">
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;
}
$(document).on('ready pjax:scriptcomplete',function(){
// Identify some stuff
var thisQuestion = $('#question{QID}');
var prevQuestion = thisQuestion.prev('.question-container');
// Listener on the checkboxes
$(':checkbox', prevQuestion).on('change', function(i) {
// Create a randomized array of the checked labels
var strings = [];
$(':checkbox:checked', prevQuestion).each(function(i) {
strings.push($(this).next('label').text());
});
shuffleArray(strings);
// Load the hidden question
$('input:text', thisQuestion).val('').trigger('keyup');
$.each(strings, function(i, value) {
$('input:text:eq('+i+')', thisQuestion).val(value).trigger('keyup');
});
});
});
</script>