- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } $(document).on('ready pjax:scriptcomplete',function(){ // Fill the array var arr = ["AX", "BX", "CX", "DX", "EX", "FX", "GX", "HX", "IX", "JX", "KX", "LX"]; arr = shuffle(arr); var thisQuestion = $('#question{QID}'); $('input[type=text]:eq(0)', thisQuestion).val(arr[0]); $('input[type=text]:eq(1)', thisQuestion).val(arr[1]); $('#question{QID}').hide(); }); </script>
Das kam ja von mir.Und jetzt ist mir noch nicht klar, was hier gemeint ist mit "dass sie sich nicht wiederholen".
<script type="text/javascript" charset="utf-8"> function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } $(document).on('ready pjax:scriptcomplete',function(){ // Fill the array var arr = []; for (var i = 1; i < 51; i++) { arr.push(("0"+i).slice(-2)); } arr = shuffle(arr); anumbers = arr.slice(0,15).join('#'); $('#question{QID} input[type="text"]').val("#"+anumbers+'#'); $('#question{QID}').hide(); }); </script>
Da musst Du Dich schon einigen. Dieser Wert wird im script fest eingetragen (arr.slice(0,15)), also hier 15.zufällig nur 13-16 Optionen