Hi, I want to give a number for each question when randomizing block. | XM Community
Skip to main content
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.
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.
@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?
> @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.

Leave a Reply