Posted By

minky on 06/05/10


Tagged

default jquery Value pixaweb


Versions (?)

PWDefaultValue - A jQuery Form-Assistant Plugin


 / Published in: jQuery
 

URL: http://www.pixaweb.co.uk/resources?tag=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

  1. /*
  2.  * @package pwDefaultValue
  3.  * @description pwDefaultValue - uses input value as a label while the input is empty
  4.  * @author Jared Clarke <[email protected]>
  5.  * @copyright 2010 (c) Jared Clarke @ Pixaweb.co.uk
  6.  * @version 0.1
  7.  */
  8. (function($) {
  9.  
  10. $.fn.pwDefaultValue = function(options) {
  11.  
  12. var opts = $.extend({}, options, $.fn.pwDefaultValue.defaults);
  13.  
  14. return this.each( function() {
  15.  
  16. var _this = $(this),
  17. _default = this.defaultValue;
  18.  
  19. _this.bind("focus", function(event) {
  20.  
  21. var _value = $(this).val();
  22.  
  23. if(_value == _default) {
  24.  
  25. $(this).val("");
  26.  
  27. }
  28.  
  29. }).bind("blur", function(event) {
  30.  
  31. var _value = $(this).val();
  32.  
  33. if(_value.length == 0 || _value == "") {
  34.  
  35. $(this).val(_default);
  36.  
  37. }
  38. });
  39.  
  40. return _this;
  41.  
  42. });
  43. };
  44.  
  45. $.fn.pwDefaultValue.defaults = {};
  46.  
  47. })(jQuery);

Report this snippet  

You need to login to post a comment.