I am trying to set embedded data fields using an if/else statement in JavaScript. I tried to come up with the correct code, but I am new to JS and what I've come up with (shown below) isn't working; the fields don't get populated.
I have created the embedded data fields in the beginning of the survey flow, so I don't think that's the issue.
Qualtrics.SurveyEngine.addOnLoad(function() {
if("${q://QID14/SelectedChoicesRecode}"!="1")
{Qualtrics.SurveyEngine.setEmbeddedData("Active_Duty_Yes", "X");
Qualtrics.SurveyEngine.setEmbeddedData("Active_Duty_No", "")}
else if("${q://QID14/SelectedChoicesRecode}"!="2")
{Qualtrics.SurveyEngine.setEmbeddedData("Active_Duty_No", "X");
Qualtrics.SurveyEngine.setEmbeddedData("Active_Duty_Yes", "")};
});
I know I can achieve the same result using branching in the survey flow, but it messes with the ability to use the Back button when taking the survey, which has to be available on this survey, so I'm looking for a JavaScript solution.
Question
Setting Embedded Data Using If/Else Statement in JavaScript
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.