How can I check the validity of an HTML5 form that does not contain a submit button?

Assuming that you have set the form element to an object called $form, then if (!$form.valid || $form.valid()) is clever syntax that means “if $form doesn’t have a method called valid, or if valid() returns true”. Typically you will have installed and initialized the jQuery Validation plugin by then, but this prevents the form from becoming disabled if the validation plugin is not loaded.

You can do a similar test using the HTML5 method checkValidity, looking something like this:

if (!$form.checkValidity || $form.checkValidity()) {
  /* submit the form */
}

EDIT: checkValidity is a function from the HTML5 forms spec. As of February 2016 CanIUse.com reports that over 95% of browsers support it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)