I am designing a survey in Qualtrics. each question has multiple choice answers, 5 fixed and 8 random, the 5 multiple choices will be constant and render all the time. I'll throw only one choice out of the 8 randomize choices to be presented with the 5 constant choices, so total multiple choices will be render is 6. Finally I need to capture in the embedded data field which choice of the 8 random was associated with the 5 fixed choices. I found this code and it works perfect But so far its capturing the IDs of the choices. however, I need to capture the label name of the item instead of the IDs.
//get the div containing the choices, then get all input child elements of that div
var choices = this.getChoiceContainer().getElementsByTagName("input");
//initialize an array for the IDs of the choices
var choiceIDs = []
//add the ID of each choice to the array
for (var i=0; i < choices.length; i++) {
choiceIDs.push(choices[i].id);
}
//get the current choice order from embedded data and add this loop to it.
//Add a | to distinguish between loops.
var choiceOrder = "${e://field/choiceorder}" + choiceIDs.toString() + "|";
//set the embedded data with the new value
Qualtrics.SurveyEngine.setEmbeddedData("choiceorder", choiceOrder);
You don't need JavaScript for this. You can just pipe the displayed choices into an embedded variable in the survey flow:
choiceorder = ${q://QIDxx/ChoiceGroup/DisplayedChoices}