Hello everyone! This time last year, I asked a question about using Javascript to save selections from a multiple choice question as separate variable. I got some great suggestions and the survey worked like a dream. JS to set embedded variables not saving on page submit
The tricky part was that I needed those variables to work on the very next page. Here is the code that I used:
Qualtrics.SurveyEngine.addOnReady(function() { var that = this; var nextButton = document.getElementById('NextButton'); nextButton.addEventListener('click', function() {
var SchoolNumberSelect = that.getSelectedChoices();
for (var i = 0; i < SchoolNumberSelect.length; i++) { switch (i) { case 0: Qualtrics.SurveyEngine.setEmbeddedData("School1", that.getChoiceVariableName(SchoolNumberSelectNi])); break; case 1: Qualtrics.SurveyEngine.setEmbeddedData("School2", that.getChoiceVariableName(SchoolNumberSelectNi])); break; case 2: Qualtrics.SurveyEngine.setEmbeddedData("School3", that.getChoiceVariableName(SchoolNumberSelectNi])); break; case 3: Qualtrics.SurveyEngine.setEmbeddedData("School4", that.getChoiceVariableName(SchoolNumberSelectNi])); break; case 4: Qualtrics.SurveyEngine.setEmbeddedData("School5", that.getChoiceVariableName(SchoolNumberSelectNi])); break; } }
for (var i = 0; i < SchoolNumberSelect.length; i++) { switch (i) { case 0: Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber1", that.getChoiceRecodeValue(SchoolNumberSelectli])); break; case 1: Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber2", that.getChoiceRecodeValue(SchoolNumberSelectli])); break; case 2: Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber3", that.getChoiceRecodeValue(SchoolNumberSelectli])); break; case 3: Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber4", that.getChoiceRecodeValue(SchoolNumberSelectli])); break; case 4: Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber5", that.getChoiceRecodeValue(SchoolNumberSelectli])); break; } }
})
});
Sadly, this code no longer works. I do not know why. The values and related logic all exist in the export of the survey, but I can’t use those fields in the survey itself, even with pages in between the question where the variable was set and where the variable is being used. This breaks the entire survey.
Has anyone run into this? Better yet, any suggestions?