Auto clear input field

Solved/Closed
thimk - Jan 12, 2009 at 11:05 AM
 loydie - Jan 14, 2016 at 09:13 PM
In http://ccm.net/contents/html/htmlform.php3, 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 response

zerokilled Posts 9 Registration date Monday January 19, 2009 Status Member Last seen January 22, 2009 1
Jan 19, 2009 at 11:22 PM
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 = "";' />
8
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.
0
Robert > angelstar
Sep 19, 2010 at 06:19 PM
Just add a boolean test... like this:

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

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