Hi, I want to give a number for each question when randomizing block. | XM Community
Skip to main content
Question

Hi, I want to give a number for each question when randomizing block.

  • November 13, 2019
  • 3 replies
  • 241 views

Forum|alt.badge.img
Hi everyone, I am super new to JS. Basically, I am randomizing my blocks but I would want subjects to know which question they. First, I put an Embedded Data "counter"=0 in the survey flow. Then, at the beginning of each block, I have a page displaying "This is question ${e://Field/counter} " Lastly, I have JS for each block like this: Qualtrics.SurveyEngine.addOnload(function() { counter=counter+1'; }); But then it does not work at all. The counter is not changing. I would appreciate it if anyone could help with this. Thanks a lot.

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • November 13, 2019
counter is a JS variable, not an embedded data field. You can update the counter in the survey flow like this: ``` counter = $e{ e://Field/counter + 1 } ``` Under your randomizer add a group for each block, then each group will contain the counter increment and a block.

Forum|alt.badge.img
  • Author
  • November 13, 2019
@TomG Thanks a lot, I tried the code, it turned with following error "Invalid JavaScript! You cannot save until you fix all errors: Unexpected token { " It seems like qualtrics is not reading the counter properly?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • November 13, 2019
> @Rui said: > @TomG Thanks a lot, I tried the code, it turned with following error > > "Invalid JavaScript! You cannot save until you fix all errors: Unexpected token { " > > It seems like qualtrics is not reading the counter properly? That line goes in an embedded data block in your survey flow, not in JavaScript.