LimeSurvey version:3 .23
Hello everyone!
I am working with a multi-choice question (q21) that includes 15 elements. I want these elements to appear in a random order that I can track. To achieve this, I first created a short free-text question (named orderq21) to generate a random order between 1 and 15. This part of the process is functioning perfectly.
However, I'm encountering a problem when trying to apply this random order to q21. Despite my efforts, q21 does not reflect the randomized sequence generated by orderq21.
Could anyone assist me with this issue? I am attaching my .lss file and the JavaScript code I used for these two questions.
Thank you in advance for your help!
orderq21 question js code:
Code:
<script>
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function fillInputWithRandomNumbers() {
var numbers = ;
for (let i = 1; i <= 15; i++) {
numbers.push(i);
}
shuffleArray(numbers);
var randomNumbersString = numbers.join(", ");
document.getElementById("answer" + "{SGQ}").value = randomNumbersString;
}
document.addEventListener('DOMContentLoaded', fillInputWithRandomNumbers);
</script>[/i]
q21 question js code:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var questionID = '{QID}';
var orderData = '{orderq21}';
var randomOrder = orderData.split(', ').map(Number);
function reorderItems() {
var parentUl = $('#question' + questionID + ' ul');
var itemsMap = {};
parentUl.children('li').each(function() {
var idNum = parseInt(this.id.replace('javatbd' + questionID, ''), 10);
itemsMap[idNum] = $(this);
});
parentUl.empty();
randomOrder.forEach(function(id) {
if (itemsMap[id]) {
parentUl.append(itemsMap[id]);
}
});
}
reorderItems();
});
</script>
Attachment not found