Something seems off, why isn't it functioning properly...
<script language="JavaScript" type="text/javascript">
//function to validate empty fields
function isEmpty(strfield1, strfield2) {
//modify field names below based on your form
strfield1 = document.forms[0].name.value
strfield2 = document.forms[0].email.value
//validate name field
if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ') {
alert( "Name is required.\nPlease fill in and try again.")
return false;
}
//validate EMAIL field
if (strfield2 == "" || strfield2 == null || !isNaN(strfield2) || strfield2.charAt(0) == ' ') {
alert(" Email is required.\nPlease fill in and try again.")
return false;
}
return true;
}
//function to check valid email address
function isValidEmail(strEmail){
validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
strEmail = document.forms[0].email.value;
if (strEmail.search(validRegExp) == -1) {
alert('A valid e-mail address is needed.\nPlease correct and retry');
return false;
}
return true;
}
//function that validates all functions, called in the onsubmit event handler
function check(form){
if (isEmpty(form.field1)){
if (isEmpty(form.field2)){
if (isValidEmail(form.email)){
return true;
}
}
}
return false;
}
</script>
This code doesn't seem to be working as expected. I'm having trouble understanding what's wrong with it, especially since I have included it in my form as well.
<form onsubmit="return check(this);" action="sendquery.php" name="contquery">