Hello,
I have a survey where a respondent is to pick from a list of options in a multiple-choice dropdown list. I have JavaScript behind this question that sets some embedded data fields to various values based on the selection. The JavaScript is in the .addOnUnload area. Basically, it's a variable list, plus the code to set the embedded data:
Qualtrics.SurveyEngine.setEmbeddedData("ApproverEmail", list[jQuery("#"+this.questionId+" select").val()]);
That's done a few times for different data fields.
This is all working quite well most of the time, but sometimes the embedded data fields are not set even though the respondent finishes the survey. I do have Force Response on the question. Qualtrics Support is not aware of any issues with JS on questions and recommended that I ask here. Is there something obvious I have done wrong? Is the JavaScript in the right place?
Embedded Data Randomly Not Set by JavaScript
Best answer by SurajK
https://www.qualtrics.com/community/discussion/comment/27312#Comment_27312Ok, in this case you will have to specify the respected list array and no need to write the type==next condition for each list, use the below code,
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
//This is the list of approver emails
var list = {
1: "example value 1",
2: "example value 2",
};
Qualtrics.SurveyEngine.setEmbeddedData("ApproverEmail",list[jQuery("#"+this.questionId).find("select").val()]);
//This is the list of approver names
var list2 = {
1: "example value 1",
2: "example value 2",
};
Qualtrics.SurveyEngine.setEmbeddedData("ApproverName",list2[jQuery("#"+this.questionId).find("select").val()]);
//etc.
}
});
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
