Solved
Generate random values using Javascript
I am using the below javascript to define an array and retrieve random elements from the array.
var COST = ["$400","$500","$600","$700","$800"];
var COST_a1 = COST[Math.floor(Math.random()*COST.length)];
alert (COST_a1) ; /* for debugging */
When I preview the survey, Qualtrics runs this piece of code TWICE. The alert box pops up twice with different values for COST_a1.
This is causing issues on another page when I try to capture the value of Cost_a1
using
this.setChoiceValue(3,COST_a1);
I only need the random value to be generated once. Any guidance on this matter is appreciated.
Thank you.
Best answer by Michael_Campbell_RedPepper
For sure! You can store it as an Embedded Data Field using this Javascript:
`Qualtrics.SurveyEngine.setEmbeddedData('FIELD', value);`
`Qualtrics.SurveyEngine.getEmbeddedData('FIELD');`
(I included the code for retrieving EDF's, too, just for kicks)
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
