Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'submit' of object #<HTMLFormElement> is not a function

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();   
like image 335
Andrew Allen West Avatar asked Sep 22 '12 05:09

Andrew Allen West


People also ask

What does JavaScript submit () do?

The method form. submit() allows to initiate form sending from JavaScript. We can use it to dynamically create and send our own forms to server.

What are object properties in JavaScript?

Object properties are defined as a simple association between name and value. All properties have a name and value is one of the attributes linked with the property, which defines the access granted to the property. Properties refer to the collection of values which are associated with the JavaScript object.

How do you return an object in JavaScript?

To return an object from a JavaScript function, use the return statement, with this keyword.


1 Answers

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.

like image 98
xdazz Avatar answered Sep 20 '22 23:09

xdazz