/ Published in: jQuery
## PWDefaultValue
This jQuery Plugin allows you to set a label-like default value on an input which is toggled depending on whether the user has entered any content into the input element. Examples and such are available on http://www.pixaweb.co.uk/resources
This jQuery Plugin allows you to set a label-like default value on an input which is toggled depending on whether the user has entered any content into the input element. Examples and such are available on http://www.pixaweb.co.uk/resources
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * @package pwDefaultValue * @description pwDefaultValue - uses input value as a label while the input is empty * @author Jared Clarke <[email protected]> * @copyright 2010 (c) Jared Clarke @ Pixaweb.co.uk * @version 0.1 */ (function($) { $.fn.pwDefaultValue = function(options) { var opts = $.extend({}, options, $.fn.pwDefaultValue.defaults); return this.each( function() { var _this = $(this), _default = this.defaultValue; _this.bind("focus", function(event) { var _value = $(this).val(); if(_value == _default) { $(this).val(""); } }).bind("blur", function(event) { var _value = $(this).val(); if(_value.length == 0 || _value == "") { $(this).val(_default); } }); return _this; }); }; $.fn.pwDefaultValue.defaults = {}; })(jQuery);
URL: http://www.pixaweb.co.uk/resources?tag=jquery