Auto clear input field [Solved/Closed]

 loydie -
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.

1 reply

Registration date
Monday January 19, 2009
Last seen
January 22, 2009
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 = "";' />
Thank you

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

CCM 2942 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 = "";' /

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!