Adding static text to text box | XM Community
Skip to main content

Adding static text to text box

  • November 1, 2022
  • 9 replies
  • 224 views

Forum|alt.badge.img+2

Hi,

I am using Javascript to display a text box when a multiple choice selection is made. (see below, text box only appears when choice is selected.)

image.pngHowever, I want to add static text in these boxes when they display: "Describe their role"

How do I do this? Here is my current Java:
image.pngThanks!

9 replies

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • November 1, 2022

chawk
You can include the below after your if logic when the box is shown. Change this with appropriate id.
jQuery(this).attr("placeholder", "Describe your role");
Hope it helps!


Forum|alt.badge.img+2
  • Author
  • 9 replies
  • November 1, 2022

TomG would you know?


Forum|alt.badge.img+2
  • Author
  • 9 replies
  • November 1, 2022

Deepak what would the ID be? Or where could I find that?

And where would I place that string of code you sent in the code? It is not working for me., I know you said after IF but where exactly?

Thanks for your help!


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • November 1, 2022

Forum|alt.badge.img+2
  • Author
  • 9 replies
  • November 1, 2022

Deepak

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

});

Qualtrics.SurveyEngine.addOnReady(function()
{

var QID= this.questionId;
   jQuery("#" + QID + " .InputText ").hide();
   jQuery("#" + QID + " input[type='checkbox']").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();
     }    
   });


 jQuery("#" + QID + " .Selection ").on("click change",function(){

    jQuery("#" + QID + " input[type='checkbox']").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();
     }    
  
   });
  
   });


});

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

});


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • November 1, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/51579#Comment_51579

Qualtrics.SurveyEngine.addOnReady(function()


{


var PLACEHOLDER = 'Describe your role';
var QID= this.questionId;


   jQuery("#" + QID + " .InputText ").hide();


   jQuery("#" + QID + " input[type='checkbox']").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();


     }    


   });




 jQuery("#" + QID + " .Selection ").on("click change",function(){


    jQuery("#" + QID + " input[type='checkbox']").each(function(){




      if(jQuery(this).prop("checked") == true)


      {


          var v1 = jQuery(this).attr("id");


        jQuery("[id*='"+v1+"~TEXT']").show().attr('placeholder', PLACEHOLDER);;


        }


      else


      {


      var v1 = jQuery(this).attr("id");


      jQuery("[id*='"+v1+"~TEXT']").val('');


      jQuery("[id*='"+v1+"~TEXT']").hide();


     }    


  


   });


  


   });



});





Use the above code.
Hope it helps!


Forum|alt.badge.img+2
  • Author
  • 9 replies
  • November 1, 2022

Thank you Deepak ! That worked


Forum|alt.badge.img+2
  • Author
  • 9 replies
  • November 8, 2022

Deepak how would I add static text to a normal text entry question? No display logic. Static text would say "please enter your suggestions here"


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • November 8, 2022

chawk
You can use the placeholder attribute:
Qualtrics.SurveyEngine.addOnReady(function() {
  var PLACEHOLDER = 'please enter your suggestions here';
  jQuery('#QR\\\\~' + this.questionId).attr('placeholder', PLACEHOLDER);
});
Hope it helps!


Leave a Reply