Return to Snippet

Revision: 42679
at March 10, 2011 04:40 by accelm


Updated Code
$('input[type=text]').focus(function(){
    if (this.defaultValue==this.value){this.value = "";}
});
$('input[type=text]').blur(function(){
    if (this.value==""){this.value=this.defaultValue;}
});

Revision: 42678
at March 9, 2011 01:59 by accelm


Initial Code
$('input').focus(function(){
    if (this.defaultValue==this.value){this.value = "";}
});
$('input').blur(function(){
    if (this.value==""){this.value=this.defaultValue;}
});

Initial URL
http://www.golfnyguide.com

Initial Description
If included in a global javascript, whenever an input receives focus it will clear the default value. If the element loses focus without any user input then it will put the default value back in there. Useful for when you aren't using <label> and putting the label in the value of the text field instead.

Initial Title
Clear all default field values for inputs

Initial Tags
forms

Initial Language
jQuery