How to clear text after selecting another option | XM Community
Solved

How to clear text after selecting another option


Userlevel 2
Badge +4

Hello all,
I currently have a question with two choices. If choice one gets selected, a text box appears. If choice 2 gets selected, no text box appears. I want the text box to clear the answer typed in the first choice if a participant were to change their mind and then select choice 2 after having already typed something in the text box for choice 1.
Will that be possible with the current javascript I am using for this question?
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery('input:text').hide();
   jQuery("[type='radio']").change(function(){
     if(jQuery(this).prop("checked") == true){
     var v1 = jQuery(this).attr("id");
     jQuery("[id*='"+v1+"~TEXT']").show();
        jQuery("[id*='"+v1+"~TEXT']").attr("placeholder", " ");
         jQuery("[id*='"+v1+"~TEXT']").css('width',500);

       jQuery("[type='text']").not("[id*='"+v1+"~TEXT']").hide();
     }else{
     var v1 = jQuery(this).attr("id");
       jQuery("[id*='"+v1+"~TEXT']").val(' ');
     jQuery("[id*='"+v1+"~TEXT']").hide();
     }

   });

});


icon

Best answer by rondev 12 May 2020, 07:15

View original

2 replies

Userlevel 7
Badge +22

Change the line above else as below:
 jQuery("[type='text']").not("[id*='"+v1+"~TEXT']").hide().val('');

Userlevel 2
Badge +4

That worked!!!! Thank you so much rondev!!!

Leave a Reply