What is the most efficient way of coding the below functions which warn people if they try to submit an empty form and also clear forms for them to enter?
$("#newsletter-subscribe").focus( function() {
if(this.value=='Your email address'){
this.value='';
}
});
$("#newsletter-subscribe").blur( function(){
if(this.value==''){
this.value='Your email address'
};
});
$("#subscribe").bind("submit", function(e){
email = $("input#newsletter-subscribe").val();
$("input#newsletter-subscribe").val(email);
if(jQuery.trim(email) == 'Your email address' || jQuery.trim(email) == '') {
alert('Please enter your email address to subscribe.');
return false;
}
});
You may want to look at the jQuery Watermark plugin.