(function($) { $.fn.inputDefault = function(options) { var settings = { text: 'fill me...', startEmpty: false, showDefault: function(){}, showInput: function(){} }; return this.each(function() { if(options) { $.extend(settings, options); } var $this = $(this); $(this).closest('form').submit(function() { if($this.val() == settings.text) { $this.val(''); } }); $(this).data('defaultText', settings.text); //$(this).attr('autocomplete', 'off'); if(settings.startEmpty) { $(this).val(''); } if($(this).attr('type') == 'password') { //Bummer, jQuery's $.clone() doesn't work for this, since we can't change the type of a clone in IE. var $clone = $('').css($(this).css()); var $this = $(this).after($clone); $clone.focus(function() { $clone.hide(); $this.show().focus(); return settings.showDefault.apply($clone); }); $this.blur(function() { if($(this).val() == '') { $this.hide(); $clone.show().val(settings.text); return settings.showInput.apply(this); } else { $clone.val($(this).val()); } }); if($(this).val() == '') { $(this).hide(); return settings.showDefault.apply($clone); } else { $clone.hide(); return settings.showInput.apply(this); } } else { $(this).focus(function() { if($(this).val() == settings.text) { $(this).val(''); return settings.showInput.apply(this); } }).blur(function() { if($(this).val() == '') { $(this).val(settings.text); return settings.showDefault.apply(this); } }); if($(this).val() == '') { $(this).val(settings.text); return settings.showDefault.apply(this); } else { return settings.showInput.apply(this); } } }); }; })(jQuery);