I have a form:
<form name="char-add" id="char-add" action="added.php" method="post"
onsubmit="charAddValidate()">
<input type="text" name="Name" id="Name" onkeyup="charNameSelected()" autocomplete="off" />
</form>
charNameSelected() simply shows the next div when something is typed into the box.
Then some Javascript code that acts on the form:
function charAddValidate() {
x = document.forms["char-add"]["Name"].value;
if (x == "" || x == null) {
alert("Name is required");
return false;
} else {
return true;
}
}
The code works, if the name is left blank it does indeed give the alert box, but if I ok this, it continues to submitting the form anyway, resulting in my php validation error 😉
Where am I going wrong (I want it not to submit the page when js validation fails). I know i’m probably missing something obvious to someone else 🙂
try adding return: