How can I hide a questions that aren't selected from a multiple choice multiple answer question? | XM Community
Skip to main content
Solved

How can I hide a questions that aren't selected from a multiple choice multiple answer question?

  • September 26, 2020
  • 9 replies
  • 125 views

Hi Everyone,
I'm constructing a survey and encountering a problem with hiding questions.
Quick run through of the situation: The first question asks respondents to select 1 or more characteristics of a product that can be improved. Each of the answers (if selected) has 3 additional questions that should be shown. For each answer not selected, those 3 additional questions belonging to the answer should be hidden and record the default choices.
After reading through many of the questions in the community, I think I need to hide questions using JavaScript so that the response will set as the default choice that it's set to.
I've tried using display logic and it will not keep the default choices because the question isn't displayed. I've tried using embedded data but I need the default choices as the response due to exporting purposes.
I attempted to use code similar to below, but it wouldn't work if multiple answers were selected. I would appreciate any help.
Qualtrics.SurveyEngine.addOnload(function() {
if("${q://QID1/SelectedChoicesRecode}"!="2") jQuery("#"+this.questionId).hide();
});
Thanks!

Best answer by TomG

You need to hide the question then loop through the selected choices and show the question if "2" is selected.
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId).hide();
jQuery.each("${q://QID1/SelectedChoicesRecode}".split(", "),function(i,val){
if(val == "2") { q.show(); return; }
});
});

View original

9 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5921 replies
  • Answer
  • September 26, 2020

You need to hide the question then loop through the selected choices and show the question if "2" is selected.
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId).hide();
jQuery.each("${q://QID1/SelectedChoicesRecode}".split(", "),function(i,val){
if(val == "2") { q.show(); return; }
});
});


  • Author
  • 5 replies
  • September 29, 2020

Hi TomG
Thanks for the help! So when using this code, the questions are shown for a short time and automatically advance. How can we make it so that the question won't advance until the next button is clicked by the respondent?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5921 replies
  • September 29, 2020

https://www.qualtrics.com/community/discussion/comment/30682#Comment_30682The code I provided above doesn't advance to the next page. So, that must be coming from someplace else (auto advance, timer question or other JS).


  • Author
  • 5 replies
  • September 29, 2020

https://www.qualtrics.com/community/discussion/comment/30689#Comment_30689Cool, it works now that I cleared everything and re-entered the code. Thank you!


  • Author
  • 5 replies
  • September 29, 2020

TomG ,
Another question: how can I make it auto advance if the question is hidden?
I tried adding an else after, but don't think I'm doing it right.. (new at JS)
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId).hide();
  jQuery.each("${q://QID90/SelectedChoicesRecode}".split(", "),function(i,val){
  if(val == "1") { q.show(); return; }
else {this.clickNextButton();}
  });
});


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5921 replies
  • September 29, 2020

'this' no longer refers to the question object inside the each(). Plus, you don't want to advance inside the loop. Try this:
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId).hide();
 jQuery.each("${q://QID90/SelectedChoicesRecode}".split(", "),function(i,val){
  if(val == "1") { q.show(); return; }
 });
if(q.is(":hidden")) this.clickNextButton();
});


  • Author
  • 5 replies
  • September 30, 2020

This new code is auto advancing for both situations. :(


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5921 replies
  • September 30, 2020

https://www.qualtrics.com/community/discussion/comment/30743#Comment_30743Change q.not(":visible") to q.is(":hidden") as shown above.


  • Author
  • 5 replies
  • October 2, 2020

Leave a Reply