krraleigh
01-11-2009, 08:43 AM
I am having a problem understanding the return value on my form validation
I thought that with the following script:
<form action="index.php" name="myform" onSubmit="return validate()">
That if my user entered invalid data and my function returned false that the forms page in question would halt the process and reload the page in question.
The code in question:
function validate (divId, theValue, typeInfo){
//instantiate object
var fvObj = new ValidatorObj();
if (typeInfo == "fName" || typeInfo == "lName"){
if(!validName(divId, theValue, fvObj))
return false;
} else if (typeInfo == "address"){
if(!validAddress(divId, theValue, fvObj))
return false;
} else if (typeInfo == "email"){
if(!validEmail(divId, theValue, fvObj))
return false;
} else if (typeInfo == "phone"){
if(!validPhone(divId, theValue, fvObj))
return false;
} else {
if(!validZip(divId, theValue, fvObj))
return false;
}
}
If my user types in the wrong zipcode I get an error message using onblur() when the user leaves the field. But, they can still submit the form to index.php, which I definately don't want to happen.
Can someone give me a heads up on what I am missing? I ran an alert against validZip() and works the way it should.
Kevin
I thought that with the following script:
<form action="index.php" name="myform" onSubmit="return validate()">
That if my user entered invalid data and my function returned false that the forms page in question would halt the process and reload the page in question.
The code in question:
function validate (divId, theValue, typeInfo){
//instantiate object
var fvObj = new ValidatorObj();
if (typeInfo == "fName" || typeInfo == "lName"){
if(!validName(divId, theValue, fvObj))
return false;
} else if (typeInfo == "address"){
if(!validAddress(divId, theValue, fvObj))
return false;
} else if (typeInfo == "email"){
if(!validEmail(divId, theValue, fvObj))
return false;
} else if (typeInfo == "phone"){
if(!validPhone(divId, theValue, fvObj))
return false;
} else {
if(!validZip(divId, theValue, fvObj))
return false;
}
}
If my user types in the wrong zipcode I get an error message using onblur() when the user leaves the field. But, they can still submit the form to index.php, which I definately don't want to happen.
Can someone give me a heads up on what I am missing? I ran an alert against validZip() and works the way it should.
Kevin