ideas regarding preventing form submission when there is JS error
Below is a snippet of the code I am using to validate a form.
Is there a way to stop the form from submitting (returning "true") if there is an error in the Javascript?
Normally, I include the form action in the JS - but I am working a team who keeps reversing my code and frankly I just dont want to deal with their unbending ideology. However, I don't want my forms to submit without passing the validation script. (Forms using this script will submit if there is a Javascript error).
//this function validates the form
function Validate() {
document.getElementById('submit_form').value="Sending...";
document.getElementById('submit_form').disabled=true;
var errfound = "false";
var errmsg = "";
var valfname = document.regform.fname.value;
if (valfname.length < 1) {
errfound = "true";
errmsg = errmsg + "Please enter a First Name. \n";
}
if (errfound == "true") {
alert(errmsg);
document.getElementById('submit_form').disabled=false;
document.getElementById('submit_form').value="Submit";
return(false);
} else {
return(true);
}
return(false);
}//end function
Is there a way to stop the form from submitting (returning "true") if there is an error in the Javascript?
Normally, I include the form action in the JS - but I am working a team who keeps reversing my code and frankly I just dont want to deal with their unbending ideology. However, I don't want my forms to submit without passing the validation script. (Forms using this script will submit if there is a Javascript error).
