Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#9704 closed enhancement (wontfix)

trigger jquery submit handlers when vanilla javascript calls form.submit()

Reported by: mcm Owned by:
Priority: low Milestone: 1.next
Component: event Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:


In asp.net linkbuttons aren't triggering my jquery form submit handlers. The problem appears to be because linkbuttons are rendered as an A tag and javascript is used to submit the form. This could apply to other frameworks too.

I propose adding a hook to the form's submit method to trigger the jquery submit handlers:

$("form").each(function() {

var oldSubmit = this.submit; this.submit = function() {

$(this).triggerHandler("submit"); oldSubmit.apply(this, arguments);



N.B. Sample code hasn't hooked up the approaches to cancelling the form submission.

Change History (5)

comment:1 Changed 12 years ago by Rick Waldron

Component: unfiledevent
Priority: undecidedlow
Resolution: wontfix
Status: newclosed

Links won't trigger a submit unless you tell them too


Version 0, edited 12 years ago by Rick Waldron (next)

comment:2 Changed 12 years ago by mcm

I think you've misinterpreted my request (I was not clear at all, the bug title was the request and the description was the reason why I want it plus a workaround I'm currently using). Basically I want to be able call submit using standard javascript (what I meant by vanilla javascript in the title):


And for this to trigger the submit event handler I've bound using jquery:

$("#form").submit(function() { ... });

This works fine with with other events like click. Here is the demonstration, sorry for not providing this before: http://jsfiddle.net/abRu4/

As you can see when run, only the hyperlink alert pops up not the form.

comment:3 Changed 12 years ago by dmethvin

That would be a significant and breaking change. Note that even without jQuery in play, the DOM form.submit() method does not call the onsubmit handler for the form.

See #4930 and #5722.

I am not sure about the architecture of ASP.NET linkbuttons but perhaps you could patch its submit method for the form so that it runs your handler and then does the submit.

comment:4 Changed 12 years ago by mcm

Cool thanks for the prompt response and links to the duplicate bug report. Sorry for not finding it before filing this one.

Indeed I hadn't realised this was the case for calling form.submit() as well. I agree with warp it's something that would be helpful to mention in the documentation, since it wasn't expected and one of the benefits of jquery is normalising behaviour.

comment:5 Changed 11 years ago by Chealer

See also #3115. Perhaps there's a documentation problem here.

Note: See TracTickets for help on using tickets.