I've written a bit of JS to validate some form fields (Im a JS newbie) but it keeps submitting the form after the errors are displayed. Could someone tell me how to stop that? I thought using return false would do it :(
function validate() {
var msg = "Please fill in the following fields: ";
if (document.contact.Full_Name.value == "") {
msg = msg + "Full Name, "
}
if (document.contact.Email_Address.value == "") {
msg = msg + "Email Address, "
}
if (document.contact.Comments.value == "") {
msg = msg + "Comments"
}
if (msg == "Please fill in the following fields: ") {
document.contact.submit();
}
else {
alert(msg);
return false;
}
}
</script>
....then:
<input type="submit" value="Send" onclick="validate();">
Thanks.
Code:
<script language="Javascript1.2"> function validate() {
var msg = "Please fill in the following fields: ";
if (document.contact.Full_Name.value == "") {
msg = msg + "Full Name, "
}
if (document.contact.Email_Address.value == "") {
msg = msg + "Email Address, "
}
if (document.contact.Comments.value == "") {
msg = msg + "Comments"
}
if (msg == "Please fill in the following fields: ") {
document.contact.submit();
}
else {
alert(msg);
return false;
}
}
</script>
....then:
<input type="submit" value="Send" onclick="validate();">
Thanks.