jquery - How to make html5 required validator work with input type=button? -


as mentioned in html5 required validator not working input type=button html5 validation not working if form button type button, not submit. there anyway make html5 validation work in case?

the html5 form validation process limited situations form being submitted via submit button. form submission algorithm explicitly says validation not performed when form submitted via submit() method. apparently, idea if submit form via javascript, supposed validation.

however, can request (static) form validation against constraints defined html5 attributes, using checkvalidity() method. if display same error messages browser in html5 form validation, i’m afraid need check constrained fields, since validitymessage property property of fields (controls), not form. in case of single constrained field, in case presented, trivial of course:

function   submitform()  {       var f = document.getelementsbytagname('form')[0];       if(f.checkvalidity())        {           f.submit();       }        else        {           alert(document.getelementbyid('example').validationmessage);       } } 

Comments