JavaScript syntax query | XM Community
Skip to main content

I'm selecting choices at a Multiple Choice (multi answer) question using JavaScript based on answers to previous Multiple Choice (multi answer) questions, so part of my js includes:
var fromQ5 = "${q://QID124/SelectedChoicesRecode}";
for (let step = 1; step < 70; step++) {
if(fromQ5.includes(step)) this.setChoiceValueByRecodeValue(step, true);
}
This works well however, if someone has selected, say, choice 56, then the js will also select choices 5 and 6 (as they 56 contains 5 and 6).
I thought I could try and embed the step var within text e.g. step + "," - but there is conflicting advice online how do that.
But also, I'm worried that won't quite solve the problem, as "56," also contains "6,".



First try to split the selectedchoice recode and store it in array. Then for arr[i] set choicevalue true.


Thanks - that worked!


Leave a Reply