Detecting the count of values in a JavaScript variable | XM Community
Skip to main content

Detecting the count of values in a JavaScript variable

  • August 13, 2022
  • 1 reply
  • 146 views

Forum|alt.badge.img+2

Hello!
I am currently running an intercept survey on our website using Website / App Feedback. The intercept is embedding a Javascript variable that can have 1 or more values and is passing that variable to the survey.
I'd like to create a new variable/field in the survey that counts the number of values in the embedded field for each respondent.
For example: Perhaps the questionnaire is surveying fast food customers after placing an online order. The intercept embeds a JavaScript variable called

condiment
which can have the values
ketchup
mustard
and/or
mayo
. In this case, I would like to create a new variable that counts the number of condiments for each respondent. So, if someone had ordered ketchup, mustard, and mayo, the new variable would return
3
, if just ketchup, it would return
1
and so on.
Is this possible?
Thanks so much for your help and generosity!

1 reply

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • August 13, 2022

Once the value of condiment ED is capatured, using JS split function you can calculate the number of elements in it and store it in new ED.