Click to See Complete Forum and Search --> : Form field onclick clearance.


no/good/at/this
12-31-2008, 04:58 AM
Hello everyone.
Ive been writing a few test forms to see what i do do not know.
This is just bugging me really, ive typed this simple form:
<form method="get" action="">
<label>Username</label><br />
<input type="text" name="username" value="username" /><br />
<label>Password</label><br />
<input type="text" name="password" value="password" /><br />
<input type="submit" value="Sign in" />
</form>

In the input fields where ive written value="", how do i get the text in the fields to clear when i click on them?
Do i need javascript for that or can it be done with good old html?
Thanks

Charles
12-31-2008, 06:15 AM
<label>Foo<input name="foo" value="Foo" onclick="this.value=''; this.onclick=function (){}"></label> You need to associate the LABEL elements with their form controls. You use JavaScript and the control's "onclick" handler. But you need to be careful, you don't want a user to go back to a field to correct the spelling and have the field clear. You only want the clearing to happen once.

no/good/at/this
12-31-2008, 03:43 PM
Thats a very good point, also one i hadn't thought of, thanks for your time.