Stay On Current Page, When Form Validation Is False
I want to stay on the current page, if the 'Name' input field is empty. Right now, it shows the error message, and when you click ok, it still goes to the next page (contactcaptcha
Solution 1:
try like so, returning your function at submit
event of the form
element
<form id="action" action="contactcaptcha.php" method="post"
onsubmit="return notEmpty(document.getElementById('Name'), 'Please enter your name')">
<fieldset>
...
<input type="submit" name="submit" value="Send your message">
</fieldset>
</form>
Solution 2:
Misssing return
keyword:
<input type="submit"
onclick="return notEmpty(document.getElementById('Name'), 'Please enter your name')"
name="submit" value="Send your message">
Solution 3:
As you use HTML5 anyway, you might want to use the required attribute: http://www.w3schools.com/html5/att_input_required.asp
<form>
<input id="message" required>
<input type="submit" value="Submit">
</form>
Post a Comment for "Stay On Current Page, When Form Validation Is False"