I am trying to pull selected choices from a multiple choice question that allows multiple selections into JavaScript. I then want to parse the choices to get each selection individually. However, when I use the suggested code for pulling selected choices into JavaScript, I am not getting any result. I have tried multiple ways of referencing selected choices, but I am still coming up with an empty array.
Qualtrics.SurveyEngine.addOnPageSubmit(function () {
var SelectedChoices = this.getSelectedChoices();
var Schools = SelectedChoices.split(', ');
var School1 = Schoolsl0];
var School2 = Schoolsl1];
var School3 = Schoolsl2];
Qualtrics.SurveyEngine.setEmbeddedData('School1',School1);
Qualtrics.SurveyEngine.setEmbeddedData( 'School2',School2);
Qualtrics.SurveyEngine.setEmbeddedData( 'School3',School3);
});
Thanks in advance for any ideas on what I am doing incorrectly.
getSelectedChoices() returns an array of choice ids.
That array appears to be empty though...I would expect to see the numeric id of the choice, right? I'm not getting that. Also, is there a way to get the text value of the choice instead of the ID?
https://community.qualtrics.com/XMcommunity/discussion/comment/45705#Comment_45705It shouldn’t be empty if you've answered the question. To confirm, use this:
console.log(this.getSelectedChoices());
Use the browser’s Inspect feature to check the console. You'll see it is an array with the choice ids.
As for getting the text, there isn't a Qualtrics function for that. You could recode the question and get the variable name (which is the label text by default) by looping through the selected choices and using getChoiceVariableName(). Alternatively (what I would do), you can find and get the label text for the selected choices directly from the DOM.
jQuery("#"+this.questionId+" input:checked").each(function(i) {
Qualtrics.SurveyEngine.setEmbeddedData("School"+(i+1),
jQuery(this).closest("li").find(".LabelWrapper>label>span").text());
});
jmaddox TomG
did you get this sorted in the end? and working for multiple choice question repopulation?
I have tried the solution above to no success, I have posted some issues identified on this new post
https://community.qualtrics.com/XMcommunity/discussion/22392/how-do-you-get-the-embedded-data-from-coded-questions-to-populate-a-follow-up-survey#latest
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.