Extract/Determine the Value of Graphic 'Selected Choice' Stored in an Embedded Value for JS Use | XM Community
Skip to main content

I have a matrix table - likert - drag and drop question. The ‘selected choices’ are images (I’ve tried setting them using the GUI and HTML tags). I’d like to read them in as embedded values (to do some math and then update the embeddedValue).

I see that it works to return the image when I pipe the embedded value for the choice, i.e. “${q://QID45/ChoiceGroup/SelectedChoicesForAnswer/1}” in a question but how do I extract the HTML of the selected choice?  Eventually I’d like to get a string but open to other ideas (new to JS). This is an example of the code I’m trying to write. 

 

// Get the value of the embedded variable
var embeddedValue = "${q://QID45/ChoiceGroup/SelectedChoicesForAnswer/1}"; /* blue tractor gas can image */

// Do something to get a string ?...



// Based on the string, do something...

switch (embeddedValue) {
case "Blue Can":
console.log("This is a blue can.");
break;
default:
console.log("Test.");
}


 

@bherbert,

Include a hidden span in your choice html with the name:

<span class='name' style='display:none'>Blue can</span>

Then have the JS add the piped value to your question and find the names:

Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery(this.questionContainer);
q.find(".QuestionText").append("<div style='display:none'>${q://QID45/ChoiceGroup/SelectedChoicesForAnswer/1}</div>");
q.find(".name").each(function() { console.log(this.innerHTML); });
});

 


Leave a Reply