Solved
Using javascript and loop-and-merge to populate a choice in a multiple choice question
I have a two-alternative multiple choice question whose alternatives are labelled "1" and "2".
I'd like to use a loop-and-merge field that contains values 1 and 2 to determine whether "1" is chosen or "2" is chosen when the question is displayed.
However, the code below throws an "unexpected {" error:
Qualtrics.SurveyEngine.addOnload(function()
{
var questionId = this.questionId;
questionID.setChoiceValue(${lm://Field/9}, true);
});
And even this code (where I've simply tried to get "1" to be chosen) doesn't work:
Qualtrics.SurveyEngine.addOnload(function()
{
var questionId = this.questionId;
questionID.setChoiceValue(1, true);
});
I'd be grateful for any help on this.
--Cheers, Mike
Best answer by MikeSmi
Ah, got it now. I needed to encompass the variable name in quotes: "${lm://Field/9}".
The code works fine now-- Thanks again!
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.