- Posts: 10
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); var input1 = $('input:text:eq(0)', thisQuestion); var input2 = $('input:text:eq(1)', thisQuestion); // Define the minimum and maximum numbers var minNumber = 1; var maxNumber = 10; // Only load random numbers once if($.trim($(input1).val()) == '' && $.trim($(input2).val()) == '') { // Create an array of possible numbers var numbers = []; var i; for (i = minNumber; i <= maxNumber; i++) { numbers.push(i); } // Shuffle the numbers array shuffleArray(numbers) // Load the first sub-question with the first number $(input1).val(numbers[0]).trigger('keyup'); // Load the second sub-question with the second number $(input2).val(numbers[1]).trigger('keyup'); } }); // A function to shuffle arrays 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>