Default Value

April 5th, 2008

A simple Javascript-based user enhancement to your web forms

The default value JQuery plug-in has been developed as a progressive enhancement for input and textfield elements. Allowing an initial value to appear within the form element, acting as a prompt for the user. This value is removed upon element focus and returned (on blur) if an alternate value has not been entered the user.

Download Javascript source file (jquery.defaultvalue.js) or example pack (.zip)

Examples

To apply the plug-in to an input element within a page:

jQuery(function($) {
    $("#input-one").defaultvalue("Your text");
});

To apply default values to multiple form elements (either input or textarea), each with a different value:

jQuery(function($) {
    $("#input-one, #input-two, #textarea").defaultvalue(
        "Input text one",
        "Input text two",
        "Textarea text"
    );
});

Download Javascript source file (jquery.defaultvalue.js) or example pack (.zip)

Comments

A simple, elegant solution. Thanks for sharing.

From Aarron Walter May 13th, 2008 at 4:52 pm

nice one. i am using it for my search box…

From Aamir Afridi July 8th, 2008 at 1:58 am