Add JavaScript Logic Based on Whether Question is Displayed | XM Community
Question

Add JavaScript Logic Based on Whether Question is Displayed

  • 1 April 2024
  • 1 reply
  • 28 views

Badge

This should be a simple question, but, for some reason, I just cannot crack it or find this information online.

I have a set of questions in a block. They are randomized so only one shows to the respondent. I want to use JavaScript to detect which one is shown and have the script take an action based on that. The approach I’ve been taking is to try to detect if it was shown and set an embedded data value to indicate whether it was shown or not. I’ve tried several different things. For example:

if (jQuery("#QID1").isHidden()) {
  Qualtrics.SurveyEngine.setEmbeddedData('Q1shown', 0);
} else {
  Qualtrics.SurveyEngine.setEmbeddedData('Q1shown', 1);
}

I was hoping to use this to use in a later if/else statement to execute some script if one question is shown rather than another.


1 reply

Userlevel 5
Badge +19

Hi @rpk ,

Instead of JS I would recommend utilizing the  survey flow for this purpose , as it is much better and simpler.
 

 

And other way using  Survey flow only is as below :
This is not so perfect but will work unless there is display logic applied on a the selected option.
Basically what I am trying to do here is if the option is shown then obviously the question will also be shown to the respondent.


Hope this resolves your query😊‼

 

Leave a Reply