How can I make sure my text entry box only appears when I click on the answer that has a entry box? | XM Community
Solved

How can I make sure my text entry box only appears when I click on the answer that has a entry box?


Badge

Hi I am trying to make sure that my text entry box only appears when I click on the option that has an entry box. I have a code that works for a multiple answer type of question but it does not work for a single answer type of questions. See below the Java Scrip.

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery('input:text').hide();
  jQuery("[type='checkbox']").change(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();
    }

  });
});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

Thanks,

icon

Best answer by rondev 5 May 2020, 13:37

View original

4 replies

Userlevel 7
Badge +22

Try the below code:
jQuery('input:text').hide();
this.questionclick = function(event,element)
  {    
    if (element.type == 'radio')
    {
      jQuery('input:text').val('').hide();
   jQuery("[id*='"+ element.id+"~TEXT']").show();
       
    }
  }

Badge

Thank you so much it is working now :)

Userlevel 2
Badge +1

Hi, I have the same issue but can not get any of these codes to work.

Badge +5

Is there JS for doing this for a multi-select?

Leave a Reply