I'm building a form that takes advantage of the new HTML5 validation methods where available. I have patterns set, required attributes etc. It all works great in supported browsers when the form is submitted, but I want to do the validation onblur. In accidentally found that I could trigger it early because on the postcode fields I have the following onblur code:
When I tabbed through those fields without entering anything (and they're required fields) the form validated them as invalid. I want to do this on all fields. I thought there would be a validate() function that I could call for example, but that doesn't appear to be the case. The only workaround I've found so far is:
That fires the validation as I want it to, but it feels to bodgy to me. Is there a proper way to do it? I don't care about browsers that don't support the validation as this is an internal form and will be validated at the server anyway, I just want to support the latest versions of FF and Chrome that we use internally at work.