0

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?

user3378165
  • 6,546
  • 17
  • 62
  • 101

1 Answers1

2

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

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236