Revision: 16890
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 18, 2009 14:05 by jonathanpglick
Initial Code
Drupal.behaviors.clearText = function(context) { var inputs = $('input.clear-text:not(.processed)'); // Store the original values inputs.each(function() { $this = $(this); $this.data('default', $this.val()); }).addClass('processed'); // Set up inputs to clear on focus & reload default (if blank) on blur inputs .focus(function() { $this = $(this); if ( $this.val() == $this.data('default') ) { $this.val(''); } }) .blur(function() { $this = $(this); if ( $this.val() == '' ) { $this.val( $this.data('default') ); } }); }
Initial URL
Initial Description
Takes any field with the class .clear-text and makes it clear it's default text (ex: 'search here') when it is focused on. If nothing is changed or the field is left blank, the original text appears when focus leaves the field.
Initial Title
Clear Text Javascript Drupal Behavior
Initial Tags
Initial Language
JavaScript