I'm very inexperienced with programming so sorry if this is stupid question.
I'm creating a form which the user will be able to submit using a button. I have used script functions to decide whether they will return true or false, with the only condition being that the input boxes must be filled. Here is a simplified version of my JavaScript and HTML code, I've only included one of the input boxes. (My real code has six)
function validateEmail() {
var x = document.forms["myForm"]["email"].value;
if (x == null || x == "") {
alert("Email must be filled out");
return false;
}
else {
return true;
}
}
<form name="myForm"
onsubmit="validateEmail()" method="post" action="Different_Page.html">
<label for="email">Email Address:</label>
<input type="email" name="email">
<input type="submit" value="Submit">
</form>
The issue is that if the user does not type in their email and the function returns false, it still goes to the page I only want it to go to when it returns true. So in other words, I want it to do nothing and stay on this page, but ONLY when the script returns false. How do I accomplish this?