Autoselecting based on selections from two previous questions | XM Community
Skip to main content
Solved

Autoselecting based on selections from two previous questions

  • March 20, 2025
  • 1 reply
  • 10 views

Forum|alt.badge.img+3

I am having trouble with a bit a script that I was hoping someone could help me with.

I have 3 multiple choice questions, all with the same response options. QID1 & QID2 are independent question, where respondents may select any number of different options. Then, when we get to QID3, I want any common options that have been selected across QID1 & QID2 to be autoselected at this question (so that I can use this to control subsequent working). 

e.g. if ‘Brand 1’, ‘Brand 3’ & ‘Brand 6’ are selected at QID1 AND ‘Brand 3’, ‘Brand 6’, ‘Brand 10’ & ‘Brand 12’ are selected at QID2, then ‘Brand 3’ & ‘Brand 6’ should be automatically selected when QID3 loads.

I was thinking something along the lines of the draft below, but this doesn’t work. Does anyone know how to fix this to function as described above? Thanks.

 

Qualtrics.SurveyEngine.addOnReady(function() { 
    var selectedChoices1 = "${q://QID1/SelectedChoicesRecode}".split(",").filter(Boolean);
    var selectedChoices2 = "${q://QID2/SelectedChoicesRecode}".split(",").filter(Boolean);

    var length = Math.min(selectedChoices1.length, selectedChoices3.length);

    for (var i = 0; i < length; i++) {
        if (selectedChoices1.includes[i] && selectedChoices2.includes[i]) {
         this.setChoiceValueByRecodeValue([selectedChoices1[i]], true);
        }
    }
});

 

Best answer by cgillon

x

View original

1 reply

Forum|alt.badge.img+3
  • Author
  • Level 2 ●●
  • 23 replies
  • Answer
  • March 20, 2025

x


Leave a Reply