Auto clear input field [Solved/Closed]

- - Latest reply:  loydie - Jan 14, 2016 at 09:13 PM
In, you give a good overall guide to forms, but omit one feature. How do folks set up input fields such that the default text is automatically erased when visitor starts to enter text? I have seen search boxes which do this. Hopefully it will require only HTML without Javascript.
See more 

1 reply

Best answer
approved by Jean-François Pillou
Registration date
Monday January 19, 2009
Last seen
January 22, 2009
Thank you
well, it actually is javascript. html don't do anything by itself. that is, html document are static and javascript add the dynamic behavior. the following is a sample code with inline javascript:
<input type='text' value='Type something...' onclick='this.value = "";' />

Say "Thank you" 8

A few words of thanks would be greatly appreciated. Add comment

CCM 6776 users have said thank you to us this month

Thank you for a great answer. However, when I use the script on my form, it does remove the default test, but the typed text also is cleared on any subsequent click.

I notice this does not happen on your Name... and Email... below. Am I missing something? Is there some other code I need?

Your help is much appreciated.
> angelstar -
Just add a boolean test... like this:

<input type='text' value='Type something...' onclick="if (!clicked) { this.value = ''; clicked=true; } " />
<input type="email" name="email" autocomplete="off">
just type

<input type='text' value='Type something...' onclick='this.value = "";' /