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

Autocode the next question based from the response in ranking order

  • March 16, 2022
  • 4 replies
  • 149 views

Forum|alt.badge.img+6

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

Best answer by Rudi

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

4 replies

Rudi
QPN Level 3 ●●●
Forum|alt.badge.img+16
  • QPN Level 3 ●●●
  • Answer
  • March 16, 2022

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


Forum|alt.badge.img+6
  • Author
  • March 16, 2022

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


Rudi
QPN Level 3 ●●●
Forum|alt.badge.img+16
  • QPN Level 3 ●●●
  • March 16, 2022

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


Forum|alt.badge.img+6
  • Author
  • March 16, 2022

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