Solved
use javascript and embedded data to randomize question formulation
Hello,
I am new to Qualtrics and I am struggling to understand how changing the embedded data works. I have the following situation. Let's say we have:
Q1: What's your best friend's name?
Q2: What's your brother's name?
and in Q3 you want to ask how old is either the brother or the best friend (picking one of these randomly). What I am currently doing is first in the SurveyFlow I create an embedded data called "chooseRandom" (with no preset value),
then, in Q3 I ask "How old is ${e://Field/chooseRandom}?" and I add the following javascript function:
Qualtrics.SurveyEngine.addOnload(function()
{
var arr = ["${q://QID1/ChoiceTextEntryValue}", "${q://QID2/ChoiceTextEntryValue}"]; #create an array with the two names
Qualtrics.SurveyEngine.setEmbeddedData('chooseRandom', arr[Math.floor(Math.random() * arr.length)]); #set 'chooseRandom' as one of those two elements
});
However, when I preview the survey the question shows simply as "how old is ?"
I think I'm simply not fully understanding how this "setEmbeddedData" function works. This is a simplified case, ideally I would want to have more conditional choices when creating the array from where to pick an element randomly, however I think if I understand this part, I can figure out the rest.
Thanks in advance!
Best answer by ilir_k
From what I understand now, when I set the embedded data element via javascript, it only shows up starting from the next block. A bit annoying, but I think it should still work in my case.
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.