A jQuery plugin that sets the default "value" for a text input.
JavaScript
Pull request Compare This branch is 1 commit ahead, 7 commits behind kbjr:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.textile
example.html
jquery.defaultText.js
jquery.js

README.textile

Default

By: James Brumond
Verison: 0.2.3
Copyright 2010 James Brumond
Dual licensed under MIT and GPL

A jQuery plugin for giving text fields customizable default values.

Description

Uses an overlaying span to give the appearance of a text field having a default value which goes away when the field is focused and comes back when the empty field is unfocused. Allows for the separate styling of the default value apart from the normal text field styles and the setting of event functions for onfocus and onblur. Default value can be set specifically from the function (eg. $('input').defaultText({ defText: 'Bob' })) or individually in the page markup by setting a “title” attribute and calling the function (eg. $('input').defaultText())

Synopsis

Object jQuery::defaultText ([ Object options ])
  options {
    [ String defText = '' ],
    [ Object textStyle = { } ],
    [ Object inputStyle = { } ],
    [ Function onfocus ],
    [ Function onblur ]
  }

Options

defText
Optional
Type: String
Sets the text to be displayed as default. If left blank, the function will check the text field’s “title” attribute and, if available, use that.

textStyle
Optional
Type: Object
A set of key-value pairs for styles to be applied to the default text.

inputStyle
Optional
Type: Object
A set of key-value pairs for styles to be applied to the text field.

onfocus
Optional
Type: Function
If given, a function that is called when the text field is focused. (this is called after the default text is hidden.)

onblur
Optional
Type: Function
If given, a function that is called when the text field is unfocused. (this is called after the default text is re-shown.)