Skip to content Skip to sidebar Skip to footer

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

<formid="action"action="contactcaptcha.php"method="post"onsubmit="return notEmpty(document.getElementById('Name'), 'Please enter your name')"><fieldset>
     ...
     <inputtype="submit"name="submit"value="Send your message"></fieldset></form>

Solution 2:

Misssing return keyword:

<inputtype="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><inputid="message"required><inputtype="submit"value="Submit"></form>

Post a Comment for "Stay On Current Page, When Form Validation Is False"