50

Can anyone explain to me what this error means? I would appreciate it a lot for any kindof help with this.

<form class="form" id="form" action="/mailer.php" method="post">

The Jquery code I'm using for it is this.

$('#form').submit();  
xdazz
  • 158,678
  • 38
  • 247
  • 274
Andrew Allen West
  • 734
  • 2
  • 7
  • 14

3 Answers3

141

Check the form to see whether there is a HTMLInputElement with id or name is submit.

This will set a property submit to the HTMLFormElement, so the submit function which is in the prototype of the form element can't be executed.

Example:

<form class="form" id="form" action="/mailer.php" method="post">
    ​<input type="button" name="submit" value="go"/>
</form>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

js:

​console.log($("#form")[0].submit)​;​  // will be the button element, not the submit function.

jQuery's .submit() method will call the .submit() on the original dom element, so the error will happen.

xdazz
  • 158,678
  • 38
  • 247
  • 274
  • 3
    There is a 'mock' submit input type="button" name="submit" so .. i'll remove the name and see if that works. – Andrew Allen West Sep 22 '12 at 05:42
  • @AndrewAllenWest Yes, that must be the reason. – xdazz Sep 22 '12 at 05:42
  • Bear in mind that jquery < 1.9 have a bug regarding the naming of submit button, ie: you cannot name submit button "submit" :) - http://jsfiddle.net/JscKb/ – eithed Mar 15 '13 at 10:57
  • 2
    That's not a bug. That's just how the underlying DOM works. There is a work around, but it doesn't work in versions of Internet Explorer that are officially supported by jQuery 1.9 and lower. – Quentin May 05 '13 at 12:57
  • 2
    Just had a damn hard time find the solution for the same problem thank you very much! – David Fariña Aug 22 '13 at 11:54
  • 2
    Great catch that should save people from banging their heads against the table. – chaseadamsio Nov 06 '13 at 00:43
28

xdazz explained the issue well.

You can use a native submit method of HTMLFormElement to work around a problem:

HTMLFormElement.prototype.submit.call($('#form')[0]);
ainokna
  • 855
  • 10
  • 18
7

If you have a button or input with the name submit or id submit, I have seen errors in IE. Make sure your inputs are correctly named. Here's an article on it http://bugs.jquery.com/ticket/1414

Ry-
  • 218,210
  • 55
  • 464
  • 476
Alex Reynolds
  • 6,264
  • 4
  • 26
  • 42