Dependent column within a side-by-side table | XM Community
Skip to main content
Solved

Dependent column within a side-by-side table


Forum|alt.badge.img+5
I have the following side-by-side table. Is it possible to only show the 'Total nights' column if the user selects overnight stay? I'm aware I can add custom validation but was hoping there would be some javascript code that could do this? !

Best answer by Anonymous

Hello @cturtle , Assuming the side-by-side question is set-up same as shown in the question image Paste the below code in the js(onReady) of the side-by-side question var that = this.questionId; jQuery("#"+that+" .SBS2").hide(); jQuery("#"+that+" input[type='radio']").on('click',function(){ var s=jQuery(this).closest(".Choice").index(); if(jQuery(this).parent().attr("class").split(" ")[1]=="c5"){ jQuery("#"+that+" th.SBS2").show(); jQuery("#"+that+" tr.Choice:eq("+s+") td.SBS2").show(); }else{ jQuery("#"+that+" tr.Choice:eq("+s+") td.SBS2 input[type='text']").val(""); jQuery("#"+that+" tr.Choice:eq("+s+") td.SBS2").hide(); if(jQuery(".c5 input[type='radio']:checked").length==0){ jQuery("#"+that+" tr.Choice td.SBS2 input[type='text']").val(""); jQuery("#"+that+" .SBS2").hide(); } } });
View original

4 replies

MsIreen
Level 5 ●●●●●
Forum|alt.badge.img+23
  • Level 5 ●●●●●
  • 456 replies
  • January 11, 2019
@cturtle You can select "Click here to edit options" and set up the logic on the column: !

  • 0 replies
  • Answer
  • January 13, 2019
Hello @cturtle , Assuming the side-by-side question is set-up same as shown in the question image Paste the below code in the js(onReady) of the side-by-side question var that = this.questionId; jQuery("#"+that+" .SBS2").hide(); jQuery("#"+that+" input[type='radio']").on('click',function(){ var s=jQuery(this).closest(".Choice").index(); if(jQuery(this).parent().attr("class").split(" ")[1]=="c5"){ jQuery("#"+that+" th.SBS2").show(); jQuery("#"+that+" tr.Choice:eq("+s+") td.SBS2").show(); }else{ jQuery("#"+that+" tr.Choice:eq("+s+") td.SBS2 input[type='text']").val(""); jQuery("#"+that+" tr.Choice:eq("+s+") td.SBS2").hide(); if(jQuery(".c5 input[type='radio']:checked").length==0){ jQuery("#"+that+" tr.Choice td.SBS2 input[type='text']").val(""); jQuery("#"+that+" .SBS2").hide(); } } });

Forum|alt.badge.img+5
  • Author
  • Level 1 ●
  • 10 replies
  • January 14, 2019
@Shashi This works perfectly. Thank you so much

Forum|alt.badge.img+5
  • Author
  • Level 1 ●
  • 10 replies
  • January 14, 2019
@Shashi Is there any chance you know the code for a similar problem? The number of contacts column should only appear if the used service checkbox is checked. !

Leave a Reply