Clearing default input values

Here is a quick and easy snippet to remove default values from input fields on focus. For each result, it clears the default value onfocus and restores the default if the value is empty onblur.

view plain print about
1(function($){ $.fn.clearDefaultVal = function(){ return this.each(function(){ var default_value = $(this).val(); $(this).focus(function(){ if ($(this).val() == default_value) $(this).val(""); }); $(this).blur(function(){ if ($(this).val() == "") $(this).val(default_value); }); }); }; })(jQuery); $('input.cleardefault').clearDefaultVal();

TweetBacks
Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.004. Contact Blog Owner