I have 15 embedded data fields filled from five different questions. Some fields could be empty. All I want to do is consolidate the list by removing any empty fields. I'm new to Javascript so my brute force method was to load the embedded data fields into an array. Use the splice method to remove any empty elements, clear the original embedded data fields and then reload them from the array.
The purpose of doing this is so that I can simply pipe in the embedded data in order, and there won't be any awkward spaces.
I'm getting the syntax error, "Invalid JavaScript! You cannot save until you fix all errors: Unexpected token ILLEGAL"
What comma or semicolon have I forgotten?
Here's the code
Qualtrics.SurveyEngine.addOnReady(function () {
let SemiList = tQualtrics.SurveyEngine.getEmbeddedData('Group1a'),
Qualtrics.SurveyEngine.setEmbeddedData('Group1b'),
Qualtrics.SurveyEngine.setEmbeddedData('Group1c'),
Qualtrics.SurveyEngine.setEmbeddedData('Group2a'),
Qualtrics.SurveyEngine.setEmbeddedData('Group2b'),
Qualtrics.SurveyEngine.setEmbeddedData('Group2c'),
Qualtrics.SurveyEngine.setEmbeddedData('Group3a'),
Qualtrics.SurveyEngine.setEmbeddedData('Group3b'),
Qualtrics.SurveyEngine.setEmbeddedData('Group3c'),
Qualtrics.SurveyEngine.setEmbeddedData('Group4a'),
Qualtrics.SurveyEngine.setEmbeddedData('Group4b'),
Qualtrics.SurveyEngine.setEmbeddedData('Group4c'),
Qualtrics.SurveyEngine.setEmbeddedData('Group5a'),
Qualtrics.SurveyEngine.setEmbeddedData('Group5b'),
Qualtrics.SurveyEngine.setEmbeddedData('Group5c')];
for (let i = 0; i < 15; i++) {
if (SemiListi]===””) {
SemiList.splice(i,1);
};
}
Qualtrics.SurveyEngine.setEmbeddedData('Group1a', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group1b', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group1c', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group2a', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group2b', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group2c', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group3a', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group3b', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group3c', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group4a', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group4b', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group4c', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group5a', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group5b', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group5c', "");
Qualtrics.SurveyEngine.setEmbeddedData('Group1a', SemiListu0]);
Qualtrics.SurveyEngine.setEmbeddedData('Group1b', SemiListr1]);
Qualtrics.SurveyEngine.setEmbeddedData('Group1c', SemiList2]);
Qualtrics.SurveyEngine.setEmbeddedData('Group2a', SemiList3]);
Qualtrics.SurveyEngine.setEmbeddedData('Group2b', SemiList4]);
Qualtrics.SurveyEngine.setEmbeddedData('Group2c', SemiList5]);
Qualtrics.SurveyEngine.setEmbeddedData('Group3a', SemiList6]);
Qualtrics.SurveyEngine.setEmbeddedData('Group3b', SemiList>7]);
Qualtrics.SurveyEngine.setEmbeddedData('Group3c', SemiList"8]);
Qualtrics.SurveyEngine.setEmbeddedData('Group4a', SemiList59]);
Qualtrics.SurveyEngine.setEmbeddedData('Group4b', SemiList'10]);
Qualtrics.SurveyEngine.setEmbeddedData('Group4c', SemiListD11]);
Qualtrics.SurveyEngine.setEmbeddedData('Group5a', SemiLists12]);
Qualtrics.SurveyEngine.setEmbeddedData('Group5b', SemiList.13]);
Qualtrics.SurveyEngine.setEmbeddedData('Group5c', SemiList14]);
});
Page 1 / 1
You don't need JS for this. Just merge them in the data and analysis tab or towards the end of your survey by creating a new field.
Alternatively, since you are putting respondents in different groups, do you really need different fields or would one suffice?
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.