Referencing previous question answer choice for conditional embedded data using javascript | XM Community
Skip to main content

This is a simplification of a problem that I am having that requires javascript.

Let's say I have two questions in the same page:

Q1: Please choose one:

  • Tim

  • Bob

  • New partner

Q2: [in-page display logic: conditional on Q1=="New Partner"] Please type their name: [text entry]

I want to set embedded data if there is new partner. Let's say I put the javascript in Q2. How would I reference Q1 answer choice so that I can say "if Q1=="New Partner" then set Q2 text entry as embedded data"? I understand I can reference the id of the current question by doing this.questionId but how does that work with the previous question or any other question? Or maybe I can condition the javascript on whether Q2 is shown somehow?

Hi adstr_bepp,
Could you not just set the Q2 text entry as embedded data every time (ie; don't check Q1 at all, as it is taken care of via display logic)? If Q2 is empty, it won't write anything to the embedded data.
If not, you should be able to do something like this:
var x = "${q://QID1/ChoiceGroup/SelectedChoices}"; //replace QID1 with relevant question ID

if(x == "New Partner") {
var partner = jQuery('#' + this.questionId).text();
Qualtrics.SurveyEngine.setEmbeddedData('My_Data', partner);
}
May need some tweaking but that's the general gist.
Good luck!


https://community.qualtrics.com/XMcommunity/discussion/comment/48371#Comment_48371Hey bgooldfed, thanks for the response! Yes, I could do your first point makes it simpler.


Leave a Reply