1

I am using asp.net mvc 3 client validation. I am trying to do some stuff before any form is submitted. I found JQuery's validation has a submitHandler that seems to be what I am looking for but I am having problems with the syntax. T

I've tried the following but I get a syntax error.

 $(function () {
    submitHandler: function (form) {
      //my logic
      alert('here');
    }
  });

Thanks for any help!!!

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
B Z
  • 9,363
  • 16
  • 67
  • 91

1 Answers1

4

You need to call this as part of the .validate() options, like this:

$(function() {
  $("#formID").validate({
    submitHandler: function(form) {
      //my logic
      alert('here');
    }
  });
});
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • I tried that and for some reason didnt seem to work. However I tried: $("form").validate({ as I need to do this for all forms. – B Z Dec 22 '10 at 02:32
  • @B Z: The text inside the $("..") is a selector: http://api.jquery.com/category/selectors/. You can change the selector to meet your needs--in Nick's example, the validate function is being called on the form with an id of formID. – Andrew Whitaker Dec 22 '10 at 04:00
  • @Andrew Whitaker - yeah, i got that, I think I know the issue. I was expecting submitHandler to happen before/during validation, not after. I can't find an event that happens before/during validation? – B Z Dec 22 '10 at 15:13
  • I will add my comment in a follow up question...thanks everyone – B Z Dec 22 '10 at 15:23