Prev Demo
Raise HTML 5 Form Validation Error Explicitly
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Raise HTML 5 form validation error explicitly</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> </head> <body> <h3>Raising HTML5 form validation error explicitly on click on link or image </h3> <form action="post.html" method="post" id="formEmail"> Email: <input type="email" name="MyEmail" required /> <input type="submit" style="display:none;" /> <a href="javascript:SubmitForm()">Submit Form</a> </form> <script> function SubmitForm() { var $myForm = $('#formEmail'); if (!$myForm[0].checkValidity()) { // not valid, submit. Will cause HTML5 error messages. $myForm.find(':submit').click(); } else { $myForm.find(':submit').click(); } } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output