Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

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

Maria
Maria DubaiCommunity Member, Qualtrics Brand Admin Qubie ✭
edited July 20 in Custom Code

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,

Best Answer

  • rondev
    rondev Community Member Wizard ✭✭✭✭✭
    Accepted Answer

    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();
           
        }
      }
    

Answers

  • Maria
    Maria DubaiCommunity Member, Qualtrics Brand Admin Qubie ✭

    Thank you so much it is working now :)

  • Simin
    Simin Community Member, Qualtrics Brand Admin Qubie ✭

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

  • Krulong
    Krulong IndianapolisCommunity Member, Qualtrics Brand Admin Qubie ✭

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