Conditionally show Text box | XM Community
Skip to main content
Solved

Conditionally show Text box

  • June 24, 2020
  • 2 replies
  • 167 views

Forum|alt.badge.img+4

For single or multi select question, we can add a text entry to any radio button.
is there is a way to hide it and only show it if the associated button is selected?

image.png

Best answer by rondev

Paste the below code in the JS of the single choice question:
 var QID= this.questionId;
   jQuery("#" + QID + " .InputText ").hide();
 jQuery("#" + QID + " .Selection ").on("click change",function(){

    jQuery("#" + QID + " input[type='radio']").each(function(){

      if(jQuery(this).prop("checked") == true)
      {
          var v1 = jQuery(this).attr("id");
        jQuery("[id*='"+v1+"~TEXT']").show();
        }
      else
      {
      var v1 = jQuery(this).attr("id");
      jQuery("[id*='"+v1+"~TEXT']").val('');
      jQuery("[id*='"+v1+"~TEXT']").hide();
     }    
   });
   });
For multi choice selection, just change word - 'radio' to 'checkbox' in the above code

2 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • June 24, 2020

Paste the below code in the JS of the single choice question:
 var QID= this.questionId;
   jQuery("#" + QID + " .InputText ").hide();
 jQuery("#" + QID + " .Selection ").on("click change",function(){

    jQuery("#" + QID + " input[type='radio']").each(function(){

      if(jQuery(this).prop("checked") == true)
      {
          var v1 = jQuery(this).attr("id");
        jQuery("[id*='"+v1+"~TEXT']").show();
        }
      else
      {
      var v1 = jQuery(this).attr("id");
      jQuery("[id*='"+v1+"~TEXT']").val('');
      jQuery("[id*='"+v1+"~TEXT']").hide();
     }    
   });
   });
For multi choice selection, just change word - 'radio' to 'checkbox' in the above code


Forum|alt.badge.img+1
  • September 10, 2020

https://www.qualtrics.com/community/discussion/comment/27093#Comment_27093Hey rondev I tried running this on "on ready" and "on load" event however it dont work. Am I missing something?