Hi All,
Please could someone explain why Qualtrics is saying there is an 'unexpected identifier' in this code. I've checked this using the action code task as that highlights errors but it says it's fine.
The purpose of the code is upon submitting the page (clicking next) i want to convert any piped text strings to their actual values and then save it as a embedded field. Doing it this way saves sooooo many branches and setting up extra embedded fields.
For instance, a Multiple Choice question is answered by selecting options 1 and 3 = QC_Food_Venue_2_Name, Coffee Shop
This is how the question answers show up in the Data and analysis section because option 1 is piped from an embedded field.I want to convert the embedded data string to its actual value. Here's the code I've prepared. I've tested parts of it using JSFiddle and the parts all seem to work (eg testing my .replace and .startswith code) so I assume I have missed something off that Qualtrics needs but JSFiddle doesn't.
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
var that = this;
if(type == "next") //listens for the next button
{
var arr = that.getSelectedChoices(); //saves the selected choices to a variable
var arr_split = arr.split(","); //splits the selected choices into an array assuming the delimeter is ', '
//cycle through the array and test for an embedded field string.
for(i = 0;i
{
//manipulate the embedded field name to use in the getembeddeddata function and replace the original variable
arr_split[i] = Qualtrics.SurveyEngine.getEmbeddedData(arr_split[i].replace("${e://Field/","").replace("}",""));
}
}
//save the whole array to an embedded field
Qualtrics.SurveyEngine.setEmbeddedData('Q211_Dining_Lunch_Locations', arr_split);
}
});
Hope someone can help
Also, can I assume that I can set an embeddeddata field in the way I have from an array? Perhaps it will include unwanted double quotes? I need to get this working in Qualtrics obviously to find out but if I can get some guidance on that too then that would be great.
Thanks
Rod Pestell
==UPDATE==
so I spotted the i=0 had a typo so the above code if now fixed but still doesn't work and I think this is because of my lack of knowledge and understand of qualtrics and how you use embedded fields and questions within JavaScript. I played about a bit and found that if I place in the next question:
Qualtrics.SurveyEngine.setEmbeddedData("Q211_Dining_Lunch_Locations","${q://QID211/ChoiceGroup/SelectedChoices}");
This seemed to provide the true value names and write it to the embedded field. That seems terribly easy, have I missed something?!
Question
JS code to Create a text set based on Selected Choices converting piped text string to actual value
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.