- Posts: 112
- Thank you received: 6
Ask the community, share ideas, and connect with other LimeSurvey users!
<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>