views:

226

answers:

3

I'm having a little problem with jQuery: I'm having .submit() defined on a form, when I submit the form by clicking the submit button, the even triggers and things works smoothly, however, when I use document.forms[0].submit(), the event doesn't get triggered, but the form submits!! Is there any reason why? How can I overcome that?

A: 

This may sound strange but why do you even use document.forms[0].submit() when you use jQuery already.

Simple (maybe stupid?) suggestion: Don't use document.forms[0].submit() use this instead

$("#hereidofyourform").submit()
jitter
+1  A: 

That's just the way it works - calling the native .submit() doesn't trigger the javascript event handler.

Use the jQuery .submit() instead:

$('form:first').submit();
Greg
+1  A: 

If the submit form is named like this

<form method="POST" id="the_waffle_form">

Then you can submit it by doing this.

$("#the_waffle_form").submit();

Check out the documentation for more great examples.

Ólafur Waage