Side navigation
#3115 closed bug (wontfix)
Opened July 02, 2008 03:38AM UTC
Closed July 02, 2008 02:39PM UTC
Last modified September 19, 2012 11:56PM UTC
document.formName.submit() is not caught by .submit() binding
Reported by: | jstayton | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.3 |
Component: | event | Version: | 1.2.6 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When a form is submitted via document.formName.submit(), it is not caught by the .submit() function bound to the form.
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>jQuery .submit() example</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('form[name="testForm"]').submit(function() { alert('Submitted!'); return false; }); }); </script> </head> <body> <form name="testForm" action="submitExample.html" method="post"> <input type="text" name="textField" value="Press submit" /> <input type="submit" name="submitButton" value="Submit" /> <input type="button" name="submitButton" value="Submit with document.testForm.submit()" onclick="document.testForm.submit();" /> </form> </body> </html>
The 'Submit' button is properly caught (and an alert displays), but 'Submit with document.testForm.submit()' is not.
I think this is how it works natively. Calling form.submit() will simply skip the handlers.
Use $(form).submit() instead.