Adding "optional" to open text box | XM Community
Skip to main content

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.

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.


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(" inpututype=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😊!!


@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
 

 


@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?


@Hathorn

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


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 :)


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("inputytype=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