jQuery Plugin – Form Field Default Value

by Jason on August 24, 2008

Note: find the latest version of this plugin on Github!

So I just finished writing my first jQuery plugin!  The idea behind it is simple – provide a dead simple way to apply a default value to any text-based form field.

In it’s current state, my plugin accomplishes the following:

  1. Provides a simple way to apply a default value to any text-based form field.
  2. Only shows default value for EMPTY form fields.
  3. Default value returns to an empty form field when it’s lost focus.
  4. Upon submitting the form, fields which still contain the default value are set to empty

Example Usage:

$(“#myfield”).DefaultValue(“My Default Value..”);

View Demo

Download

I’m sure there are other plugins that satisfy these requirements and I’m not claiming that this is the best in the world, but it satisfies all my requirements and gave me the opportunity to develop my first jQuery Plugin!

I may enhance the plugin soon to incorporate styling to form fields.