I have the following which I use for submitting forms on my site:
<a onclick="document.forms['REGform'].submit(); return false;" class="button" href="javascript:;">Register</a>
I have inputs within the form with the required tag but this does not seem to fire them? Meaning doesn’t stop empty inputs being submitted.
If I use a normal submit button it works fine by the way – is onclick not a recognised way to submit a form within html5?
The problem is the
submit()method, not the use ofonclick(although you can’t avoid the former if you want to submit using JS instead of HTML).Submitting using JS causes the form’s validation steps to be skipped (although you can re-implement them in JS (with
checkValidity()).— http://www.w3.org/TR/html5/forms.html#dom-form-submit
— http://www.w3.org/TR/html5/association-of-controls-and-forms.html#form-submission-algorithm