Hi,

It´s a simple plugin, that let you clear and reset the value of input
elements.

Example of usage:

$(function() {
 $('input').resetDefaultValue(); // for all input elements
 $('input.className').resetDefaultValue(); // for some elements
 $('#q').resetDefaultValue(); // for a especific element
});

The plugin code:

/**
 * jQuery resetDefaultValue plugin
 * @version 0.9
 * @author Leandro Vieira Pinho <[EMAIL PROTECTED]>
 * How to use
 * $(function() {
 *      $('input').resetDefaultValue(); // for all input elements
 *  $('input.className').resetDefaultValue(); // for some elements
 *      $('#q').resetDefaultValue(); // for a especific element
 * });
 * ChangeLog
 * 0.1 - First relase
 * 0.2 - Filter input elements with type igual text, just it.
 * 0.9 - Rewrite all the plugin code. Thanks to Klaus Hartl [
http://groups.google.com/group/jquery-en/browse_thread/thread/5ca50fd021062331
]
 */
jQuery.fn.resetDefaultValue = function() {
        function _clearDefaultValue() {
                var _$ = $(this);
                if ( _$.val() == this.defaultValue ) { _$.val(''); }
        };
        function _resetDefaultValue() {
                var _$ = $(this);
                if ( _$.val() == '' ) { _$.val(this.defaultValue); }
        };
        return
this.filter('[EMAIL 
PROTECTED]').click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
}

The resetDefaultValue plugin has borned here:
http://groups.google.com/group/jquery-en/browse_thread/thread/5ca50fd021062331

Reply via email to