Auto clear input field [Solved/Closed]

thimk - Jan 12, 2009 at 11:05 AM - Latest reply:  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.
See more 

5 replies

Best answer
zerokilled
Posts
9
Registration date
Monday January 19, 2009
Last seen
January 22, 2009
- Jan 19, 2009 at 11:22 PM
7
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 = "";' />

Thank you, zerokilled 7

Something to say? Add comment

CCM has helped 1597 users 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.
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; } " />
<input type="email" name="email" autocomplete="off">
just type

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