Need some help. I'd like to count the number of responses to a certain multiple choice question that is part of a loop. I can get the number of responses to the question from the following:
var item_count= "${q://QID1/SelectedChoicesCount}";
I add embedded data: DSCOUNT to the survey flow at the start of the survey, and intitialize that to 0
But I am unable to operate on that as a number
var DSCount = Qualtrics.SurveyEngine.getEmbeddedData('DSCOUNT');
var item_count= "${q://QID1/SelectedChoicesCount}";
DSCount = DSCount + item_count;
Qualtrics.SurveyEngine.setEmbeddedData( 'DSCOUNT', DSCount);
Any suggestions?
Thanks in advance!
Cindy
Solved
Embedded Data in Javascript to count overall number of responses to a question in a loop
Best answer by ahmedA
The embedded variables are always returned as strings, so based on your current code, you are just concatenating them. If you change to the following, it should start working properly:
var DSCount = Number(Qualtrics.SurveyEngine.getEmbeddedData('DSCOUNT'));
var item_count= Number("${q://QID1/SelectedChoicesCount}");
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.