Solved
using javascript to create/visualize randomized embedded data in the same question
Hi all,
I'm looking for directions as I (have to) start using java. I'm programming an experiment where participants will be asked to repeatedly choose between two options called A and B.
What would you prefer between these two options?
Option A: xx amount of dollars at time [time level],
Option B: yy amount of dollars at time [time level], where the time level is randomly picked from five levels. Becas
where the time level of option A is randomly picked from three levels [now, 1 week from now, 2 weeks from now] and the time level of option B is randomly picked from five levels [1 week from now, ... , 5 weeks from now]. Furthermore, the time level of Option B must always be greater than the time level of Option B [e.g. if A=1week then B>1week]. This design ended up to be too complicated to be managed within the Qualtrics Survey Flow, so my only way out is to write some lines of java in each question. This Java script should create the five time levels as embedded data, randomly pick one level to be used in Option A and one in Option B (with time B level > time A level) and then I'd show these embedded data as piped text in the question.
I used all the previous contributions about this topic but it's not working the way I hoped. Specifically, when I use java I can't create and visualize an embedded data within the same question. The only way I can make it working is by creating a variable in, let's say, Question Q10 like this:
Qualtrics.SurveyEngine.addOnload(function()
{
Qualtrics.SurveyEngine.setEmbeddedData('time','one week from now');
});
and then, in the following question Q11, write the following:
Qualtrics.SurveyEngine.addOnReady(function()
{
Qualtrics.SurveyEngine.getEmbeddedData('time');
});
If I do this, in Q11 I can put time as piped embedded data in the question and see the "one week from now" text visualized.
I tried to put both .set and .get instructions in the same script same question but in this way nothing is visualized in the question.
Any way that I can just put .set and .get lines together and get the variable visualized all in the same question?
Thank you very much for any help you may give.
Best answer by TomG
> @calmac said:
> Hi Shashi,
> thank you for your reply, still I'm not sure how you think this should be used to address my problem. What do you mean, if possible can you please articulate a bit more?
@Shashi means you can't use embedded data. Instead of assigning your random time levels to embedded variables, assign them to JS variables. Then instead of piping embedded variables, update the html with JS. So your choices (html) would be something like this:
```
xx amount of dollars at time <span id="aTime"></span>
yy amount of dollars at time <span id="bTime"></span>
```
Then, assuming you assign your random time levels to JS variables aTime and bTime you would update the choices with JS as follows:
```
jQuery("#aTime").html(aTime);
jQuery("#bTime").html(bTime);
```
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.