Default text in a response that disappears when clicked on | XM Community
Skip to main content
Solved

Default text in a response that disappears when clicked on


James_Byrne_Kantar
Forum|alt.badge.img
How do we set default text that can disappear when a text box is clicked on? A client has a verbatim question and in this box needs to provide some instruction about not entering personal details here. I have set a default text response but the customer has to manually delete this before providing their response and also can submit this default text as a response. I need something that works in the same way as the email and name fields in the attached image, an example is provided to give you an idea of the format required, but when you click in the text disappears. How can this be done in the survey? !

Best answer by TomG

Use JavaScript to add a placeholder attribute to the input element. ``` jQuery("#"+this.questionId+" .InputText").attr("placeholder", "My placeholder text"); ```
View original

37 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • Answer
  • March 15, 2018
Use JavaScript to add a placeholder attribute to the input element. ``` jQuery("#"+this.questionId+" .InputText").attr("placeholder", "My placeholder text"); ```

James_Byrne_Kantar
Forum|alt.badge.img
thanks again! @TomG

khalid
Forum|alt.badge.img+1
  • 4 replies
  • April 10, 2018
> @TomG said: > Use JavaScript to add a placeholder attribute to the input element. > ``` > jQuery("#"+this.questionId+" .InputText").attr("placeholder", "My placeholder text"); > ``` > Can this also work in the Form text type? because when i used it it shows me First name in all the fields.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • April 10, 2018
> @khalid said: > > Can this also work in the Form text type? because when i used it it shows me First name in all the fields. That line of JS adds the placeholder to all the elements in the question with a class of InputText. For a text form, you'd need to modify it to add specific placeholders to specific fields.

khalid
Forum|alt.badge.img+1
  • 4 replies
  • April 10, 2018
Thanks Tom, i will try to find out the specific placeholder for each field.

Forum|alt.badge.img+3
  • Level 1 ●
  • 24 replies
  • October 3, 2018
I had the same question. By adapting the info TomG sent, I was able to change all of my textarea default text with a jQuery loop in the theme footer like this. If each of your textareas need a different message, then (of course) this won't work. <script> Qualtrics.SurveyEngine.addOnload(function() { jQuery("textarea").each(function() { jQuery(this).attr("placeholder","Enter your comments here."); }); }); </script>

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • October 3, 2018
@red - You shouldn't need a loop...that's the beauty of jQuery. This should work: ``` <script> Qualtrics.SurveyEngine.addOnload(function() { jQuery("textarea").attr("placeholder","Enter your comments here."); }); </script> ```

EllenW
Forum|alt.badge.img+2
  • 4 replies
  • October 23, 2019
@TomG , thank you for the code. I'm still at an early level of qualtrics and can't figure out how to implement your solution for disappearing default text/placeholder text ("attribute" and "input" haven't turned up any useful resources in the community) . Are you able to point to any more resources showing the step-by-step process? Thank you! !

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • October 23, 2019
> @EllenW said: > @TomG , thank you for the code. I'm still at an early level of qualtrics and can't figure out how to implement your solution for disappearing default text/placeholder text ("attribute" and "input" haven't turned up any useful resources in the community) . Are you able to point to any more resources showing the step-by-step process? Thank you! > > ! > Your image doesn't have a JS icon on the left, which means you haven't added the JavaScript. Click on the cog, select Add JavaScript, and paste the JS from the accepted answer above into the addOnload function.

EllenW
Forum|alt.badge.img+2
  • 4 replies
  • October 23, 2019
@TomG that works beautifully, thank you!!!

  • 2 replies
  • November 19, 2019
Hi, Can I apply this same coding to a multiple choice question with an "other" option with text entry? Screenshot is attached below.

Forum|alt.badge.img+1
  • 2 replies
  • December 10, 2019
@TMartin53 did you get an answer to this? I have the same question.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • December 10, 2019
> @TMartin53 said: > Hi, > > Can I apply this same coding to a multiple choice question with an "other" option with text entry? Screenshot is attached below. Yes.

  • 2 replies
  • December 17, 2019
@rwh - This worked for me: jQuery("#"+this.questionId+" .InputText").attr("placeholder", "Please Explain.");

Forum|alt.badge.img
  • 14 replies
  • January 15, 2020
@TomG Hey Tom, jQuery("#"+this.questionId+" .InputText").attr("placeholder", "Please Explain."); I tried this code for my case but doesn't seem to be working. It is placing a placeholder text but it disappears when a customer starts typing in the box. My requirement is the default text should disappear when the customer clicks in the box. I tried doing it with on-click/onfocus functionality but it didn't help. Can you please help?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • January 15, 2020
> @Sugra said: > @TomG Hey Tom, > jQuery("#"+this.questionId+" .InputText").attr("placeholder", "Please Explain."); > I tried this code for my case but doesn't seem to be working. It is placing a placeholder text but it disappears when a customer starts typing in the box. My requirement is the default text should disappear when the customer clicks in the box. I tried doing it with on-click/onfocus functionality but it didn't help. Can you please help? That's the way placeholders work. You can use a focus event to remove the placeholder attribute to get the desired functionality.

Forum|alt.badge.img
  • 14 replies
  • January 16, 2020
@TomG Thank you for responding Tom I tried below code for focus event but doesn't seem to be working. Can you help me if I am doing anything wrong here? { /*Place your JavaScript here to run when the page loads*/ jQuery("#"+this.questionId+" .InputText").attr("placeholder", "Please Explain."); jQuery("#" + this.questionId + " .InputText").focus(function(){ jQuery("#"+this.questionId+" .InputText").removeAttr("placeholder", "Please Explain."); }); });

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • January 16, 2020
> @Sugra said: > @TomG Thank you for responding Tom > I tried below code for focus event but doesn't seem to be working. > Can you help me if I am doing anything wrong here? > { > /*Place your JavaScript here to run when the page loads*/ > jQuery("#"+this.questionId+" .InputText").attr("placeholder", "Please Explain."); > jQuery("#" + this.questionId + " .InputText").focus(function(){ > jQuery("#"+this.questionId+" .InputText").removeAttr("placeholder", "Please Explain."); > }); > }); Your removeAttr syntax is wrong. Change to .removeAttr("placeholder");

Forum|alt.badge.img
  • 14 replies
  • January 16, 2020
@TomG This is still not working. I tried below code as well but no help jQuery("#"+this.questionId+" .InputText").attr("placeholder", "Please Explain.").onfocus="this.placeholder = ''";

  • 6 replies
  • April 12, 2020

TomG

Hi Tom thanks for your guidance, need your help. Can you show how to the text comment in multiple text boxes?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • April 12, 2020

@Fahad,
The code provided will add a placeholder to all the textarea elements on the page. Change the jQuery selector as needed.


  • 6 replies
  • April 13, 2020

TomG : Hi Tom, it works with a single text box, however doesn't work with multiple text boxes in the same question


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5923 replies
  • April 13, 2020

TomG : Hi Tom, it works with a single text box, however doesn't work with multiple text boxes in the same question
I forgot .attr() only works on the 1st element in the set, use .each():
jQuery("#"+this.questionId+" .InputText").each(function() {
jQuery(this).attr("placeholder", "My placeholder text");
});


  • 6 replies
  • April 20, 2020

TomG
Thanks :)... will try.
Another question on the topic of changing logo. I already have existing static template with everything (color, format) in place. However since our logo changed this year someone had put in placed Custom CSS code for the new logo while everything (formatting and color) remains same. I mistakenly removed the Custom CSS code.
Can you help me how to write the custom CSS code?


  • 6 replies
  • April 20, 2020

TomG: Sorry for asking so many questions i am very new to Qualtrics.
I found the below link used in one of the earlier study, what I understand is that the logo is being removed and replaced with background in url. Now if I need to do the same how do I develop the url?
Please help, appreciate it
html .Skin #Logo {display: none;}
#SurveyEngineBody {
  background: url(https://etihad.eu.qualtrics.com/CP/Graphic.php?IM=IM_86xvhpypazMDskl) no-repeat fixed;
 -webkit-background-size: cover;
 -moz-background-size: cover;
 background-size: cover;
}


Leave a Reply