Created
October 16, 2009 22:37
-
-
Save drywall/212128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery Resettable - A function to make form fields reset to their initial values when left blank | |
* Copyright (c) 2009 Ben Byrne - ben(at)fireflypartners(dot)com | http://www.fireflypartners.com | |
* Dual licensed under MIT and GPL. | |
* Date: 10/16/2009 | |
* @author Ben Byrne | |
* @version 0.1.0 | |
* | |
*/ | |
jQuery.fn.resettable = function ( ) { | |
fields = new Array(); | |
this.each(function() { | |
//check to make sure the element has a name attribute. If not, do nothing! | |
if (!jQuery(this).attr("name")) return true; | |
fields [ jQuery(this).attr("name") ] = jQuery(this).val(); | |
jQuery(this).focus(function() { | |
if ( jQuery(this).val() == fields[ jQuery(this).attr("name") ] ) jQuery(this).val(""); | |
}).blur(function() { | |
if (jQuery(this).val() == "") jQuery(this).val( fields[ jQuery(this).attr("name") ] ); | |
}); | |
}); | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment