views:

80

answers:

3

I was having trouble determining what was cause my form to not submit when I called

$('#form').submit();

through javascript (but submitted fine when I clicked on the submit button). So I add this piece of code for testing:

$('#form').live('submit', function()
{
    alert('submitting form');
    return true;
});

Now when I click the submit button, the alert displays and then the form submits. When I call:

$('#form').submit();

through javascript, the alert displays however the form does not submit. Now I am pulling the form through ajax onto a modal window so not sure if that has anything to do with it. Anyone know what might be causing this issue?

+2  A: 

The submit event is not supported with the live function.

From the jQuery API:

In jQuery 1.3.x only the following JavaScript events (in addition to custom events) could be bound with .live(): click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup. As of jQuery 1.4 the .live() method supports custom events as well as all JavaScript events. As of jQuery 1.4.1 even focus and blur work with live (mapping to the more appropriate, bubbling, events focusin and focusout). As of jQuery 1.4.1 the hover event can be specified (mapping to "mouseenter mouseleave").

Jacob Relkin
I tried switching the submit button input type to button instead of submit and made the .live() event a click on that button. The ajax request in the .live event runs fine, it still does not execute the form.submit() method when called through javascript in that click event.
ryanzec
Did you try what I put in my answer. Would have thought that would have worked.
A: 

Try calling submit() on the HTMLFormElement object:

$("#form")[0].submit();

Same results?

Jeremy
Would do the same as $("#form").submit(); as id's can only be used once. Unless you meant $("form")[0].submit();
A: 
$("#form").trigger('submit');

???

RueTheWhirled