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.
}
});
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
