Return to Snippet

Revision: 41978
at February 25, 2011 17:15 by f6design


Initial Code
$('.default-value').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
	    this.value = '';
	    $(this).css('color', '#000');
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            $(this).css('color', '#999');
	    this.value = default_value;
	}
    });
});

Initial URL

                                

Initial Description
If your HTML form fields have a 'watermark' default value, it will be removed when the field is focussed and replaced if focus is lost (and the user has left the field blank).

To use give your form field a class of 'default-value'

Initial Title
Remove/restore a form field's default value on focus/blur

Initial Tags
form

Initial Language
jQuery