Hide Question Based on Likert Response - JavaScript Help Needed | XM Community
Skip to main content
Solved

Hide Question Based on Likert Response - JavaScript Help Needed


Show first post

28 replies

qualtrics_nerd
Level 5 ●●●●●
Forum|alt.badge.img+19
  • Level 5 ●●●●●
  • 225 replies
  • December 19, 2023
Fatma wrote:

@vgayraudThank you so much for the code. it worked as expected, but upon testing, if the user clicked next button without answering the second question QID35, it hid the question and did not show the error message

the user have to click again on any radio button (except NA) so it show the second question
any idea how to fix that?
thanks,

You can use this below updated code to account for  the above scenario:

 

Qualtrics.SurveyEngine.addOnReady(function()
{


if (this.getSelectedAnswerValue(1) !== "6"  && this.getSelectedAnswerValue(1) !== null ) 
{ 			
	jQuery("#QID35").show();
}
else {
	jQuery("#QID35").hide();
		}



	this.questionclick = function(event, element) {
	if (this.getSelectedAnswerValue(1) !== "6"  && this.getSelectedAnswerValue(1) !== null ) { 	jQuery("#QID35").show();
		}
 else {
		jQuery("#QID35").hide();
				   }
    	}
});


Hope this resolves your query😊!!


qualtrics_nerd
Level 5 ●●●●●
Forum|alt.badge.img+19
  • Level 5 ●●●●●
  • 225 replies
  • December 19, 2023

Hi @Fatma ,
Please use below updated code to accommodate above scenario:

 



Qualtrics.SurveyEngine.addOnReady(function()
{


if (this.getSelectedAnswerValue(1) !== "6"  && this.getSelectedAnswerValue(1) !== null ) 
{ 			
	jQuery("#QID35").show();
}
else {
	jQuery("#QID35").hide();
		}



	this.questionclick = function(event, element) {
	if (this.getSelectedAnswerValue(1) !== "6"  && this.getSelectedAnswerValue(1) !== null )
 { 	jQuery("#QID35").show();
		}
 else {
		jQuery("#QID35").hide();
				   }
    	}

});


Hope this resolves your query😊!!


vgayraud
QPN Level 6 ●●●●●●
Forum|alt.badge.img+49
  • QPN Level 6 ●●●●●●
  • 395 replies
  • December 20, 2023

Hi,

Adapt the first part of the code with @qualtrics_nerd ‘s answer. You need to check if a valid answer is checked before hiding the second question.


Leave a Reply