user3378165 user3378165 -4 years ago 113
jQuery Question

Validate 2 forms using jquery validation

On my MVC project I have a View with 2 forms.

I validate the forms using jquery validation.

How can I validate 2 forms on submit of one of them?

I tried that:

$(function () {
$("#form1").validate();
$("#form2").validate();
$.extend($.validator.messages, { required: "*", email: "Invalid email address." })
});


But only the second form gets validate but the first one don't, any idea on how to solve that?

Answer Source

Try

$("#form1").on("submit",function(e) { 
  if ($("#form1").valid() && $("#form2").valid()) { 
    console.log("great job"); 
  else e.preventDefault(); 
});

For alternatives

Validating multiple forms on the same page

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download