Adding "optional" to open text box | XM Community
Question

Adding "optional" to open text box

  • 9 February 2024
  • 7 replies
  • 86 views

Userlevel 3
Badge +11

Is there a way to have “optional” in a dithered box (or something similar) within the text box and then it would disappear as soon as the recipient starts typing? 

I know the other option would be to just state (optional) after the question - wanting to know if there’s a way to display it within the actual text box.


7 replies

Userlevel 6
Badge +21

Hello @kgillis ,

Adding the text "(Optional)" directly into the Survey Question itself would simplify the process. You can utilize default choices to keep this static text visible even as the survey begins. Customers have the option to remove the text using the back key on the keyboard if they desire. Alternatively, employing JavaScript allows you to write code and incorporate it into your survey for achieving the same outcome.

Userlevel 5
Badge +19

Hi @kgillis ,

You can add below JS code to your question to achieve the same :

 

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

});

Qualtrics.SurveyEngine.addOnReady(function()
{


jQuery(" input[type=text]").eq(0).attr("placeholder", "optional");


});

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

});

Hope this resolves your query😊!!

Userlevel 3
Badge +11

@qualtrics_nerd 

I entered the JS exactly as you posted (*this also has fueled me to learn JS)

But I am not seeing the “optional” in the text box show up as anticipated
 

 

Badge

@qualtrics_nerd 

This code works great for Single Line text entry boxes! Thank you.  How would I change the JS code so that it works on Multiple Lines and Essay Text box types?

Userlevel 7
Badge +36

@Hathorn

Try adding below code
jQuery(‘#’+this.questionId+' .InputText').attr("placeholder", "optional");

Badge +1

Hi @kgillis  ,

Looks like you are using multiple lines or an essay box within text entry question type. Please try the below code if that works:

 

jQuery("textarea").attr('placeholder',"optional")

 

Hope this helps :)

Userlevel 4
Badge +8

Hi @Hathorn ,

Try adding the below code.This code will add the "optional" placeholder text to both single-line text input fields and multiline text input fields.

 

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

Qualtrics.SurveyEngine.addOnReady(function() {
    // Add placeholder attribute to single-line text inputs
    jQuery("input[type=text]").attr("placeholder", "optional");
    
    // Add placeholder attribute to multiline text inputs (textarea)
    jQuery("textarea").attr("placeholder", "optional");
});

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

 

 

 

Thank You!

Leave a Reply