JavaScript syntax query | Experience Community
Skip to main content
Solved

JavaScript syntax query

  • Feb 3, 2022 11:55 AM UTC
  • 2 replies
  • 78 views

MikeW
Level 5 ●●●●●
Forum|alt.badge.img+14
  • Level 5 ●●●●●

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,".



Best answer by grahulp5

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

View original

2 replies

grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+18
  • QPN Level 3 ●●●
  • Answer
  • Feb 3, 2022 8:22 PM UTC

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


MikeW
Level 5 ●●●●●
Forum|alt.badge.img+14
  • Author
  • Level 5 ●●●●●
  • Feb 10, 2022 9:50 AM UTC

Thanks - that worked!