Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Clear default text in textarea when in focus

Hi there,

I have a contact form that has three input fields and one textarea field for comments. I have used some javascript plug-ins to clear the default text when in focus for the input fields but I'm not sure how to do it with the textarea field. If anyone could help me or point me to the right direction, it would be greatly appreciated.

Let me know if you need me to submit the tutorial I used or line of code(s).

Thank you.

1 Answer

Why not just use the placeholder attribute?

 <textarea placeholder="Placeholder text here..."></textarea> 

Hi there,

I currently have placeholder active in my code with the text "Leave A Message." I would like the effect to match my input fields for continuity.

You could use the placeholder attribute on input fields as well.

Yes, I originally had that before applying the clear default text method. However, when the user clicked on the field, the text cursor would be placed at the end of it and would not automatically overwrite or clear the current message. (i.e. If the input field said "name", the text cursor would come after the e and if someone started typing it would become "namealex.") It just seemed inefficient to have the user delete the text inside in order to write new content to contact me.

This may have been something I incorrectly coded but that was my experience with it so I didn't really like using it.