I'm asking a "check all that apply" question (Question 1) and want to use items on the list of Selected Choices (e.g., the first item on the list) in a subsequent question (Question 2).
I would think that there are two approaches:
1) use JavaScript in Question 1 to define the embedded fields for use in Question 2; or
2) use a function in the text for Question 2 that refers back to the Selected Choices in Question 1 to get the values.
I'm indifferent as to which approach I use - just one that works.
When I tried approach 1, using the following JavaScript:
Qualtrics.SurveyEngine.addOnPageSubmit(function ()
{
var choicesall = this.getSelectedChoices();
let choicesarray = choicesall.split(",");
Qualtrics.SurveyEngine.setEmbeddedData('origstring', choicesall);
Qualtrics.SurveyEngine.setEmbeddedData('numofchoices', choicesarray.length);
for (i = 0; i < choicesarray.length; i++) {
var selectedchoice = choicesarray[i]
var embfieldname = "choicenumber" + i;
Qualtrics.SurveyEngine.setEmbeddedData(embfieldname, selectedchoice);
}
});
the embedded variables, such as origstring, numofchoices, etc. are blank.
When I try approach 2, I know that I can use a construct like ${q://QID1/ChoiceGroup/SelectedChoices}. I get the full list of selected choices correctly. But is there a modification to the function call that pulls out item i from the list?
Any suggestion would be most appreciated.
Thanks!
Question
Defining embedded fields from Selected Choices of same question using JavaScript
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.