Solved
How does qualtrics give value to a sequence of variable in a loop?
Hi, I would like to give values to a sequence of global variable in qualtrics.
To illustrate, I have set var1, var2, var3 in the survey flow. and I have define data=['apple', 'banana', 'orange'] in the javascript. I am using the following script.
Qualtrics.SurveyEngine.setEmbeddedData('var1', data[0]);
Qualtrics.SurveyEngine.setEmbeddedData('var2', data[1]);
Qualtrics.SurveyEngine.setEmbeddedData('var3', data[2]);
Is there a way to do it in a loop? For example, I am thinking
for (i = 0; i < rd_option1.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData('var+i', data[i]);
}
But it seems like qualtrics does not read 'var+i' properly in a loop? Is there a way to solve it?
Thank you very much!
Best answer by TomG
It should be:
```
for (i = 0; i < data.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData("var"+(i+1), data[i]);
}
```
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
