Hi,
Since it is my first to use javascript,
I did not talk about javascript.
In your sample survey there was no script, and no script is needed.
Your sample is fine.
Here the structure
And G2 is hidden by condition. Just add the other 150 questions here.
You only have to enter the same "Randomization group name" to ALL questions (200).
And I will not do this.
Of course you can consider a different approach.
If you insist in using javascript.
Use the previous scrip. This only selects 8 numbers out of 200.
Again all questions get the same randomization group name.
And you display the 8 questions by condition
Let's call the question of type "short text" where you inserted the script and got the string with the 8 selected numbers Q1.
The condition of the first question is: strpos(Q1,'-1-')>0
The condition of the second question is: strpos(Q1,'-2-')>0
The condition of the third question is: strpos(Q1,'-3-')>0
...
The condition of the 100. question is: strpos(Q1,'-100-')>0
...
The condition of the 200. question is: strpos(Q1,'-200-')>0
You CAN do that, but it is more unnecessary work.
And you can consider a third approach.
Again select the eight numbers by javascript, well the structure should be a bit different.
Store these 8 numbers in a question of type "multiple short text" with eight subquestions.
Like this.
Code:
<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, hier Zahlen von 1 - 200
var arr = [];
for (var i = 1; i < 201; i++) {
arr.push(i);
}
arr = shuffle(arr);
$('#question{QID} input[type="text"]:eq(0)').val(arr[0]);
$('#question{QID} input[type="text"]:eq(1)').val(arr[1]);
$('#question{QID} input[type="text"]:eq(2)').val(arr[2]);
$('#question{QID} input[type="text"]:eq(3)').val(arr[3]);
$('#question{QID} input[type="text"]:eq(4)').val(arr[4]);
$('#question{QID} input[type="text"]:eq(5)').val(arr[5]);
$('#question{QID} input[type="text"]:eq(6)').val(arr[6]);
$('#question{QID} input[type="text"]:eq(7)').val(arr[7]);
$('#question{QID}').hide();
});
</script>
In a question of type "huge text" you store all 200 definitions of the applicants like this
Now with the string functions "strpos()", and "substr()" you find the row and can insert the right text into the question.
This way you only need 8 questions insted of 200.
Joffm