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

Conditionally show Text box

  • Jun 24, 2020 6:14 AM UTC
  • 2 replies
  • 186 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

View original

2 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • Jun 24, 2020 6:36 AM UTC

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
  • Sep 10, 2020 4:54 AM UTC

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?