How do I write a Javascript line to add the just selected choice to an embedded data field?

ironspiderironspider Santa Monica, CACommunity Member Qubie ✭

How do I write a Javascript line to add the just selected choice to an embedded data field?

Greetings all, so I have a situation where I create and initialize a embedded data field to "0" at the start of my survey flow. Then, I have a question later in the survey that, if seen, updates that value. If the respondent doesn't see that question the embedded data field should not be changed. So I want to include a bit of Javascript on that particualr question that essentially says "when the answers this question set the embedded data field to the selected choice." So when I put this following code in any of the three Javascript sections (addOnload/addOnReady/addOnUnload) it doesn't work. What am I missing? I think maybe I need to wrap this javascript with something else that watches for the question to be answered?

Note that this code does work if I put it at the end of the survey in a question everyone sees but then it screws up my initial setting and initialization of the embedded data field. Again, this should be attached to the question (QID123 in my example) so that it is only changed if the person sees and answers that question.

Qualtrics.SurveyEngine.setEmbeddedData("FOO","${q://QID123/ChoiceGroup/SelectedChoices}");

Answers

  • YashYash IndiaCommunity Member - Trial User Qubie ✭

    Hi,

    I just want to let you know if you are putting the javascript code in the same question from which you are picking the value then it wouldn't work. You need to put at least one question between the source question and the final question in which you are trying to show the data. Try to write your JS code in the next question which so it can populate properly. Please see the below screenshot, it is working fine for me.

    randomize block

    Also, you have an alternative solution for this. Instead using javascript you can set the embed data from survey flow as shown below. In this case, you don't need to create one extra question as previous, it will directly get the value of the embedded variable.

    randomize block

  • ironspiderironspider Santa Monica, CACommunity Member Qubie ✭

    Thanks Yash. After my original post I thought about it and I actually did end up going the Survey Flow route. It actually ended up working well with the "initializing" of the Embedded Data fields angle. Thanks for the response!

Sign In to Comment