Autocode the next question based from the response in ranking order | XM Community
Skip to main content

Anyone who can help with the javascript? I need to autocode the 3rd question based from my responses in Rank Order questions. Below is the link for reference.

https://rochediacx.fra1.qualtrics.com/jfe/preview/SV_6zmQqumcohFkWa2?Q_CHL=preview&Q_SurveyVersionID=current

Hi there,
this could solve your problem :-)

  1. create an embedded data field selectedItemsRankingQuestion

  2. add the below code into the JS for the ranking question

  3. add the below code in the ranking question

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
let inputs = document.getElementsByTagName('input')
let selectedItemsRankingQuestion = new Array;
console.log(inputs)
for(let i=0;i if(inputs[i].attributes.type = "text" && document.getElementById(inputs[i].id).value.length > 0 && inputs[i].id !="NextButton") {

selectedItemsRankingQuestion.push(inputs[i].id.split('~')[2])
}
}
console.log(selectedItemsRankingQuestion)
Qualtrics.SurveyEngine.setEmbeddedData("selectedItemsRankingQuestion", selectedItemsRankingQuestion.join(','));
});
then add this code in the multi-select question:

Qualtrics.SurveyEngine.addOnload(function()
{
let selectedItemsRanking = "${e://Field/selectedItemsRankingQuestion}".split(',')
for(let i = 0;i this.setChoiceValueByRecodeValue(selectedItemsRanking[i],1)
}
});

note that the recodes for these two questions have to be identical respectively that the recodes of the auto coding question are identical with the last element of options' ids in the ranking question

Best regards

Rudi


Rudi Thanks you, it worked. But after adding some questions, the auto coding question selects all the options.

https://rochediacx.fra1.qualtrics.com/jfe/preview/SV_6zmQqumcohFkWa2?Q_CHL=preview&Q_SurveyVersionID=current


Hi, I think the easiest way would be to add page breaks. Minimum would be before and after the ranking question and before and after the hidden question. Side note: Page breaks are also better for mobile devices because they avoid scrolling for the respondents 😉
Best regards

Rudi


Thanks for that Rudi . I'll suggest that to our client. Thanks again.


Leave a Reply