-1

I have a form that has multiple inputs which are validated with HTML5 validation. When I submit the form with by clicking the submit button it works fine. However, when I want to submit this form using jQuery's .submit() it does not validate the form.

How can I force jQuery to validate the form before it is submitted?

Chris
  • 6,914
  • 5
  • 54
  • 80
MJ X
  • 8,506
  • 12
  • 74
  • 99
  • Possibble Duplicate of [this](http://stackoverflow.com/questions/13541133/jquery-form-submit-validation) – Ashrith Sheshan Jun 27 '13 at 06:53
  • @AshrithSheshan That question is about using a validation plugin, not HTML5. – Barmar Jun 27 '13 at 07:08
  • No my question is that i validated all my forms with html5 required attribute so now i need to submit my form with jquery because i have put inputs for serial numbers that is checked with ajax if it is not exist in the database. so i need to submit my for with jquery and do call other functions after that which checks for correct serial number. when i submit with jquery the html5 validation is not triggered. – MJ X Jun 27 '13 at 09:10

2 Answers2

0

You could use jQuery to do a click on the submit button instead of submitting the form with JavaScript directly. So the validation should work as when you click on the button youself.

MoYapro
  • 119
  • 1
  • 8
0

I understand that you are doing the following steps and it fails.

$('#yourform').validate();
    if ($('#yourform').valid()) 
    {
        $('#yourform').submit();
}

If not, this shoud work.

You should open your site with Firefox, try to submit and press CTR+SHIFT+J. It will pop up the Java Error Console. Try to see if there isn't any syntax error.

Angela
  • 27
  • 6