[jQuery] Show/Hide Sibling
Hi,
I have written a quick form validation script that checks if form
fields are empty, and if so, returns a visual cue (through an error
message) that the field is required:
$('.error').hide();
$(".submit").click(function() {
var name = $("input#name").val();
if (name == "") {
$("label#name_error").show();
$("input#name").focus();
}
var email = $("input#email").val();
if (email == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
});
My question is this:
1. How do I hide the error message once the field is filled in, and,
2. How do I prevent the form from being submitted until all fields are
filled in?
Best,
Justin