I'm a bit new to all this so am looking for some help please.
I am trying to validate a form:
<form method="post" name="form" action="thanks.php" style="height: 76px" onsubmit="javascript:return Validate(this)">
What happens is, the IsEmpty part works fine on all three fields but it does not continue on to validate the email address (isValidEmail)- it just posts without checking it.
<SCRIPT LANGUAGE="JavaScript">
function Validate(){
if(IsEmpty(form.fullName)) {
alert("Please enter your name");
form.fullName.focus();
return false;
}
if(IsEmpty(form.email_add)) {
alert("Please enter your email address");
form.email_add.focus();
return false;
}
if(IsEmpty(form.phoneNum)) {
alert("Please enter a contact telephone number");
form.phoneNum.focus();
return false;
}
if(isValidEmail(form.email_add.value)){
alert("Your email address is not valid, please re-enter");
form.email.focus();
return false;
}
return true;
}
function isValidEmail(str) {
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function IsEmpty(aTextField) {
if ((aTextField.value.length==0) ||
(aTextField.value==null)) {
return true;
}
else { return false; }
}
</SCRIPT>
Jan