geeky · non php code

Javascript Error: submit is not a function

Just my luck and I ran into the dreaded submit is not a function javascript error.

Here’s the scenario.

While coding javascript along, you get a form via id or name on your html page and calls the submit() function on it. You think it should just behave as expected (submits the form) instead nothing happens and in firebug, you get a submit is not a function error. You are like WTF is going on? You start to wonder if you remembered the syntax correctly so you do some research and all the pages tell you yes it’s just submit() and nothing else.

Finally you start to search on the error “submit is not a function” you get to this page and you learned:

The reason was the statement “formObj.submit();” in the javascript was colliding (resulting in ambiguity within the browser) with the form button, which was also named “submit”.

So just rename the element within the form tag that is named “submit” will fix the problem.

Here’s an example.

HTML:

<form id="search"><input name="something" /><input type="submit" name="submit" /></form>

Javascript:

function submitForm() {
  document.getElementById('search').submit();
}

gives “submit is not a function” error.

Change HTML to:

<form id="search"><input name="something" /><input type="submit" name="NOT_SUBMIT" /></form>

5 thoughts on “Javascript Error: submit is not a function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s