Determining loop row number via JavaScript for computed texts | XM Community
Solved

Determining loop row number via JavaScript for computed texts

  • 11 April 2019
  • 4 replies
  • 12 views

Userlevel 3
Badge +9
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.
icon

Best answer by TomG 11 April 2019, 20:31

View original

4 replies

Userlevel 7
Badge +27
You can use:
```
parseInt("${lm://CurrentLoopNumber}");
```
Userlevel 3
Badge +9
I think this might work - going to test it out and will get back to the thread!
Userlevel 7
Badge +27
> @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.
Userlevel 3
Badge +9
Works as expected! Thanks TomG! I actually ended up using this to solve other loop related issues.

Leave a Reply