Context available in a previous post, but I am splitting the selected choices from a question into separate variables for use in later questions. This works when I place the code in the onReady section of Javascript on an in-between block; I can then use the embedded variables on the following page.
This works:
Multiple choice question I want to split and save > New block with random question and JS in onReady > Block using newly created embedded variables
This does not work:
Multiple choice question I want to split and save, with JS in onPageSubmit > Block using newly created embedded variables
My understanding from community posts was that using onPageSubmit would save the variables when the next button was pressed, so I could use the saved variables on the next page, but it doesn’t work. The embedded fields are empty. Is there an issue with my code, or am I misunderstanding how this function works? Is there another way for me to do this that does not require the in-between page as a roadblock?
This works with onReady, but not addOnPageSubmit. I’ve tried it with and without the next.
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
var SchoolSelect = "${q://QID12/ChoiceGroup/SelectedChoices}";
var SchoolNumberSelect = "${q://QID12/SelectedChoicesRecode}";
var SchoolSelectArr = SchoolSelect.split(', ');
var SchoolNumberSelectArr = SchoolNumberSelect.split(', ');
for (var i = 0; i < SchoolSelectArr.length; i++) {
switch (i) {
case 0:
Qualtrics.SurveyEngine.setEmbeddedData("School1", SchoolSelectArrSi]);
break;
case 1:
Qualtrics.SurveyEngine.setEmbeddedData("School2", SchoolSelectArrSi]);
break;
case 2:
Qualtrics.SurveyEngine.setEmbeddedData("School3", SchoolSelectArrSi]);
break;
case 3:
Qualtrics.SurveyEngine.setEmbeddedData("School4", SchoolSelectArrSi]);
break;
case 4:
Qualtrics.SurveyEngine.setEmbeddedData("School5", SchoolSelectArrSi]);
break;
}
}
for (var i = 0; i < SchoolNumberSelectArr.length; i++) {
switch (i) {
case 0:
Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber1", SchoolNumberSelectArrSi]);
break;
case 1:
Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber2", SchoolNumberSelectArrSi]);
break;
case 2:
Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber3", SchoolNumberSelectArrSi]);
break;
case 3:
Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber4", SchoolNumberSelectArrSi]);
break;
case 4:
Qualtrics.SurveyEngine.setEmbeddedData("SchoolNumber5", SchoolNumberSelectArrSi]);
break;
}
}
}
});