It DOES NOT return false and is not showing the error. See jfiddle http://jsfiddle.net/paYAp/2/
My JavaScipt:
function validateForm() {
var error = "";
var x=document.getElementById('fname').value;
var y=document.getElementById('lname').value;
/*
Additional variable defined here, commented out for debugging
*/
if ((x==null || x=="") || (y==null || y==""))
{
error += "-First and last name required. <br />";
}
/*
There were additional statements here, commented out for debugging
*/
if (error != ""){
alert(error);
//document.getElementById('error').innerHTML = "Error: " + error;
return false;
}
}
I’ve also attached onsubmit="return validateForm()" to the form.
Can someone please take a look for me and tell me if I’m missing something?
You may not actually be returning
false, you may be returningundefinedas you do not returntrueif validation passes.This will trick you into thinking your validation is correct, when it isn’t.
Adding
return true;to the end of the function may prove that you are not returning false after all.