I have been trying to run a very simple js code on Qualtrics for about 5 hours now.
There are 3 blocks:
- Block 1 captures a numeric value (say p)
- Block 2 creates an embedded value (say embedVar =-99)
- Block 3 captures another numeric value (say r)
- Within Block 3, on a new page, I want to display the embedded variable embedVar = r/p.
For this I am running the following js code:
var p ="${q://QID7/ChoiceTextEntryValue}" ;
var r = "${q://QID2/ChoiceTextEntryValue}" ;
var result = Math.ceil(r/p) ;
Qualtrics.SurveyEngine.setEmbeddedData( 'embedVar', result );
This just does not work. I have tried to put it on “onload”, “onunload”, “onsubmit”, “onready” (please don’t mind the case-insensitivity). I have put this code in the page where I record the response r, the page where I am supposed display the updated embedVar. I exhausted every combination. It just remains -99 or it shows a 0.
What does work is if I equate embedVar to p, it does show the actually recorded p. This makes me suspect that the js is not running at the appropriate time. Can anyone please help? It is a very simple code that is supposed to work, but it just doesn’t to work.
To note: The block 3 runs a loop where, in every loop, the value p is recorded and I try to update the embedVar and try to display it.