I have a JavaScript method that i want to validate a form
if the validation fails so
if (validationChecks ...... ){
return alert("message")
}
else{
//proceed
}
however no matter what i do in the if the form still seems to submit, any ideas?
I have a JavaScript method that i want to validate a form
if the validation fails so
if (validationChecks ...... ){
return alert("message")
}
else{
//proceed
}
however no matter what i do in the if the form still seems to submit, any ideas?
you should return false after checking validation.
if (validationChecks ...... ){
alert("message")
return false; }
else{
//procced
}
You have spelt 'return' wrong. Also, returning an alert will not work, you'll need to return false explicitly to stop the form submitting.
if (validationChecks ...... ){
alert("message");
return false;
}
else{
//procced
}
Your validation must return false when the form is not valid, and if you're calling your validationin onSubmit, then you must make sure that you include a return statement there as well:
<form onSubmit="return validationChecks();">
I think "return" is better than "reutrn". An error is thrown, but you don't see it as the page is reloaded.