Determining loop row number via JavaScript for computed texts | XM Community
Skip to main content
Solved

Determining loop row number via JavaScript for computed texts

  • April 11, 2019
  • 4 replies
  • 34 views

Forum|alt.badge.img+9
  • Level 2 ●●
  • 61 replies
Hi Qualtrics community - I have a complicated text fill situation which I THINK would be easier to deal with if I could add a JavaScript OnReady computation for the current row of a loop, but I don't know how to determine what row I'm on via JavaScript. Below is the scenario: Q1 "At what age did you start smoking regularly?" ___ age Q2 "At what age did you stop smoking?" ___ age [Begin Loop] Row 1: represents X to 17 Row 2: 18 to 24 Row 3: 25 to 29 Row 4: 30 to 34 etc. up to 70+ category CIGLIFE "About how many of the years from age [X] to age [Y] did you smoke cigarettes?" On loop 1, X = lower bound of the loop OR Q1 if appropriate Y = upper bound of loop OR Q2 if appropriate Example: if on ROW 2 and Q1 = 15 and Q2 = 23 then the text would read: "About how many of the years from age 18 to 23 did you smoke cigarettes?" I feel like if I could determine what row of the loop I'm currently on during the OnReady then I could update the text displayed on the screen dynamically.

Best answer by TomG

You can use: ``` parseInt("${lm://CurrentLoopNumber}"); ```

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • Answer
  • April 11, 2019
You can use: ``` parseInt("${lm://CurrentLoopNumber}"); ```

Forum|alt.badge.img+9
  • Author
  • Level 2 ●●
  • 61 replies
  • April 12, 2019
I think this might work - going to test it out and will get back to the thread!

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • April 12, 2019
> @Pete_L said: > I think this might work - going to test it out and will get back to the thread! I had a typo that I corrected above. There is no 't' in parse.

Forum|alt.badge.img+9
  • Author
  • Level 2 ●●
  • 61 replies
  • April 16, 2019
Works as expected! Thanks TomG! I actually ended up using this to solve other loop related issues.