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

How to clear text after selecting another option

  • May 12, 2020
  • 2 replies
  • 84 views

Forum|alt.badge.img+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();
     }

   });

});


Best answer by rondev

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

2 replies

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

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


Forum|alt.badge.img+4
  • Author
  • Level 1 ●
  • May 12, 2020

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