Hello,
I have been trying to get this JS form validation code to work ad nauseam... it won't validate, stop if required and submit. The best I managed was to get it to display an empty field alert but still submit.
I think the problem lies with the form syntax but I tried different variations and still couldn't get it to work properly; the code is here:
-
function formValidator()
-
{
-
var firstname = document.getElementById("firstname");
-
//..rest of the fields}
-
if(isEmpty(firstname, "Please enter a value"))
-
{//..input check, rest of fields}
-
return true;}
-
return false;}
-
[html]
<form name="theform" id="theform" action="insert_val.php" method="post" onSubmit="return formValidator()">
//..rest of form input with id='firstname'
<input type="button" value="Add" onclick="submit()" />
[/html]
Any suggestions for the syntax to use so the form is checked when submit is pressed, stops submit if there's an empty field then allows me to submit again?