views:

36

answers:

1

I want to trigger a form submit, but not have my usual handlers for that form's submit be called. I could just unregister any listeners, before calling, but that feels ugly (and specific to form submits since they're the only type of event that I can guarantee will be the last to occur).

A: 

You do not need to unregister your event handlers; they will not be invoked when you fire the event programmatically...

document.forms[0].onsubmit = function() {
  alert("You will not see this");
  return false;
}
document.forms[0].submit();

However, if you have a jQuery object, be sure to call the submit function of the underlying DOM element...

$("form")[0].submit();
Josh Stodola