Hi there,
the "easiest" way would be:
- add a question with 50 answer options (one for each question in your survey) at the beginning of your questionnaire. The first question is for your first subset of 15 questions
- copy the question. The second question is for your second subset of 10 questions
- note that you need to add a page break between the two questions
- add this js code to the first question:
function getRandom(arr, n) {
let result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
Qualtrics.SurveyEngine.addOnload(function()
{
let allChoices = this.getChoices() //
console.log(allChoices)
for(let i =0;i
this.setChoiceValue(allChoices[i],0)
}
for(let i =0;i this.setChoiceValue(allChoices[i],0)
}
let choicesSelected = getRandom(allChoices,15)
for(let i =0;i
this.setChoiceValue(choicesSelected[i],1)
}
this.clickNextButton()
});
- then add the below js code into the second question
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
Qualtrics.SurveyEngine.addOnload(function()
{
if(jQuery(this.questionContainer).parents('.MobilePreviewFrame').length)
{
console.log('Mobile Preview - skipping rest of addOnload');
return true;
};
console.log("Running addOnload()");
let selectedChoices = "${q://QID3/SelectedChoicesRecode}".split(',')//adopt the QID to the question ID in your survey
let selectedChoicesRecodes = new Array
let allChoices = this.getChoices()
let allChoicesRecode = new Array;
for(let i=0;i allChoicesRecode.push(Number(this.getChoiceRecodeValue(allChoices[i])))
}
for(let i=0;i selectedChoicesRecodes.push(Number(selectedChoices[i]))
}
console.log(selectedChoicesRecodes)
let eligibleChoices = new Array;
for(let i=0;i {
if(!selectedChoicesRecodes.include(allChoices[i]))
{
eligibleChoices.push(allChoices[i])
}
}
//console.log(eligibleChoices)
let choicesSelected = getRandom(eligibleChoices, 10)
console.log(choicesSelected)
for(let i =0;i
this.setChoiceValue(choicesSelected[i],1)
}
this.clickNextButton()
});
please check out this link:
Lastly: you need to set a display logic on your questions based on selected answers in the two questions
https://kantarsandbox.qualtrics.com/jfe/preview/SV_06UTx5x5ejQAJb8?Q_CHL=preview&Q_SurveyVersionID=current&pT=2
Hope this helps
Best regards
Rudi
Hi there,
just out of curiosity: if I understood your requirement correctly you could also choose 25 questions out of your 50 questions ;-) There doesn't seem to be any reason why you choose 15 first and then from the remaining 35 questions 10 again.
Best regards
Rudi