Simple JavaScript Clear Default Value

June 22nd, 2005

When you want a default value to be removed when a user selects a form field to enter some text, you don’t need to go out searching for a ten line script someone has generously distributed online. While there may be merit in other ways of doing this, there is one way that only requires a single line of code.

For each field that you want to clear the initial value add the following event handler to the input element:

onfocus="this.value=''"

For more on web forms visit W3Schools.com and scroll part way down the page for the “forms and input” section.

There are, of course, better ways of doing this with unobtrusive Javascript and the DOM. This is intended as a stop gap solution, not a best practice.

Entry Filed under: Tutorials

Bookmark This: del.icio.us:Simple JavaScript Clear Default Value digg:Simple JavaScript Clear Default Value newsvine:Simple JavaScript Clear Default Value blinklist:Simple JavaScript Clear Default Value furl:Simple JavaScript Clear Default Value reddit:Simple JavaScript Clear Default Value blogmarks:Simple JavaScript Clear Default Value


About Harvey Ramer

CSS Web design, e-commerce Web design, and internet marketing issues from the desk of Harvey A. Ramer at Design Delineations.

View Harvey Ramer's profile on LinkedIn

Reader/Customer Feedback

Harvey Recommends

Accolades

Design Notes: A CSS Web Designer’s Blog at Blogged

Calendar

June 2005
M T W T F S S
« May   Jul »
 12345
6789101112
13141516171819
20212223242526
27282930  

Most Recent Posts