$('input[class*="defaulttext"]').each(function () {
this.value = $(this).attr('title');
$(this).addClass('defaultclass');
$(this).focus(function () {
if (this.value == $(this).attr('title')) {
this.value = '';
$(this).removeClass('defaultclass');
}
});
$(this).blur(function () {
if (this.value == '') {
this.value = $(this).attr('title');
$(this).addClass('defaultclass');
}
});
});
This basically adds the background text effect for textboxes (uses the title). Once selected the text goes away.
Now, I have a problem with optional fields. If the user does not edit these fields the default background text is submitted with the form. So I need to reset the value of the unedited field once the form is submitted. Any ideas how to do this?
Maybe on form submit, check if the title = value? If yes then set to ”.
Based on the code you have, you could do: