Javascript code for show and hide information | XM Community
Skip to main content
Hi all,

I plan to provide information below my question by using a picture after the multiple choice question. I hide the information through Display Logic. I attached the screenshot. If people choose, "yes, show the evidence example", a picture will be shown. !. I would like to ask if it is possible for me to hide the picture again. Some people said to me to use JS code. Can someone help me with what I should put in the Java script code? I am not familiar using javascript.

Thank you very much for your help.
Hello @Sherly ,



Paste the below code in the js(OnReady) of the multichoice question

Assuming the first option of multichoice question enables hide/show property of example image question. Also, the page have only two questions i.e Multichoice question and example image question



var that=this.questionId;

jQuery("#QID2").hide();

jQuery("#"+ this.questionId+" input[type='radio']").on('change',function(){

if(jQuery("[id='QR~"+that+"~1']").prop('checked')){

jQuery("#QID2").show();

}else{

jQuery("#QID2").hide();

}

});



Replace "QID2" with the question ID of the example image question
@Sherly,



If I understand your question correctly, you don't need JavaScript. Make your "Show the evidence" question multi-select. Then your evidence picture is a descriptive text question with in-page display logic that shows when "show evidence" is selected. When someone unselects "show evidence" the descriptive text question will be re-hidden.
I tried that one! Thanks @TomG and @Shashi !

Leave a Reply