HTML Form Effect- Remove Default Value On Focus

Image frame
HTML Form Effect- Remove Default Value On Focus
Maruf
Dec 4th, 2008
Maruf scribbled this post.

This Javascript form effect basically removes the default value (e.g Your Name) when the input field is on focus. If nothing is entered, and focus is taken away from the input field, the value is displayed again.

It’s a pretty cool effect, which I’m always using on a lot of projects. Here’s an example (click in the input field, and then click outside the input field):

1
2
3
<form>
<input type="text" value="Your Name" name="name" onblur="if (this.value == '') {this.value = 'Your Name';}"  onfocus="if (this.value == 'Your Name') {this.value = '';}" />
</form>

Filed away: Javascript

comments

Image frame
1

dude, I was just looking for this and your post saved the day, thx!

John
Jul 23rd, 2009
Image frame
2

This doesn’t work in IE7

Alex
Mar 25th, 2010
Image frame
3

Big help, thanks.

Chaz
Jul 1st, 2010
Image frame
4

Thanks Maruf. This is exactly what I was looking for, and simpler than I expected.

David Hernandez
Aug 11th, 2010

feel free to leave a scribble

Name:
Email:
gravatar
Want an image next to your comments?
visit gravatar.com
Message:
Get a free quote