- Posts: 26
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> // Start code Option 1 to 5 var uniqueRandoms = []; var numRandoms = 5; function makeUniqueRandom() { // refill the array if needed if (!uniqueRandoms.length) { for (var i = 0; i <numRandoms; i++) { uniqueRandoms.push(i); } } var index = Math.floor(Math.random() * uniqueRandoms.length); var val = uniqueRandoms[index]; // now remove that value from the array uniqueRandoms.splice(index, 1); return val; } // End Option 1 to 5 // Start code Option 6 to 8 var uniqueRandoms2 = []; var numRandoms2 = 8; function makeUniqueRandom2() { // refill the array if needed if (!uniqueRandoms2.length) { for (var i = 6; i <numRandoms2; i++) { uniqueRandoms2.push(i); } } var index = Math.floor(Math.random() * uniqueRandoms2.length); var val = uniqueRandoms2[index]; // now remove that value from the array uniqueRandoms2.splice(index, 1); return val; } // End Option 6 to 8 $(document).ready(function() { // Option 1 to 5 for (var i = 0; i < 2; i++) { var rand = 1+makeUniqueRandom(); var rand = ''+rand+''; $('#javatbd{SGQ}'+rand+'').hide(); } // Option 6 to 8 for (var i = 0; i < 1; i++) { var rand = 1+makeUniqueRandom2(); var rand = ''+rand+''; $('#javatbd{SGQ}'+rand+'').hide(); } }); </script>
You might add the version/build of LimeSurvey to prevent people applying your workaround to unsuitable LimeSurvey installations.rvenkat wrote: This has been tested on all types of arrays, including Array (Text).