Javascript Error: submit is not a function

Took me a google search to find this one, but for some reason one of my forms was not submitting using javascript.

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”.

ie:


<input type="submit" name="submit" value="Login">

Change the name of the button to "login" or something else more reflective of it's functionality instead of "submit".
javascript:


function submitForm(formId) {
  var formObj = document.getElementById(formId);
  formObj.submit();
}

html:


<a href="http://www.homepage.com"
onclick="submitForm('loginForm'); return false">Login</a>

<form id="loginForm">
<input type="submit" name="login" value="Login">
</form>
VN:F [1.8.1_1037]
Rating: 9.3/10 (11 votes cast)
VN:F [1.8.1_1037]
Rating: +2 (from 2 votes)
Javascript Error: submit is not a function9.31011

88 Responses to “Javascript Error: submit is not a function”

  1. T Grove says:

    This article is f***ing amazing, I should hire you at my company!! I have been searching all day for this stupid issue. And of course, with DOT syntax it blows my mind that IE supports this method. Submit is an object of the page, in DOT syntax it should be named differently. Thanks Again – you are a life savor!!

    Now, how in the hell to you change all those other stupid f***ing posts on Google so they get it right???

    UN:F [1.8.1_1037]
    Rating: 3.0/5 (1 vote cast)
    UN:F [1.8.1_1037]
    Rating: -1 (from 1 vote)
  2. haval says:

    THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  3. The Swede says:

    Thanx man. I just spent the last hour wondering why all funktions but submit() worked fine in my form. And there it was: a button named submit…

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  4. jeconais says:

    Well, this’ll teach me to use google first rather than try and figure it out myself.

    My wife thanks you for keeping my hair on my head, where it belongs.

    UN:F [1.8.1_1037]
    Rating: 5.0/5 (1 vote cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  5. Steve says:

    Okay, it got me too. Put me down for 5 hours wasted on a Sunday night :)

    I’m sure it was a good idea at the time, but what a hunk of junk HTML and JavaScript are. Thanks a bunch W3C. And no Bill Gates that doesn’t mean you are right, you don’t play well with others so you are completely invalid.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  6. Wee Keat says:

    Thanks for that. Just saved me hours cause I would not have thought of a name clash!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  7. Kevin says:

    YOU SOLVED MY PROBLEM!

    You rock!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  8. chovy says:

    You’re welcome!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  9. Anonymous says:

    Thank you so much – that saved me a lot of time and frusteration – very very much obliged!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  10. Mike says:

    Thanks so much. I wasted a whole day on this, but I don’t think I’ll make that mistake again.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  11. Ryan says:

    Count me as one of the ones you helped. I wasted at least a good hour of my life on this error!

    Ryan

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  12. Ian says:

    I loooooooooooooooooooooooooooooooove you!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  13. Avinash says:

    gr888888888888 work dude………!!!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  14. crazy says:

    dude, you have no idea how much pain that problem caused me… Thanks a billion.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  15. moty66 says:

    Three hours of searchin my codes and javascripts books about this error, thank you so much, you haved my ***
    moty

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  16. I know – first thing I should’ve checked when I got the unexplainable was “reserved words”.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  17. Ian Good says:

    Thanks for the tip! I spent an hour trying to figure it out before I googled it. I need to learn to google first.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  18. jon says:

    Thanks!! Luckily, I only lost 40 minutes before I found your incredibly useful article.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  19. Marko Tulio corona Pacheco says:

    Thanks man I love you,

    from Mexico with love

    It took me about 6 huurs to find your blog, Thanks again.It was so simple all time…

    Marko Tulio corona Pacheco

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  20. TracyTrace says:

    Definitely worth googling this. I wasted about 30 minutes on this before finding your post. Thanks!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  21. Oscar González says:

    Thanks!
    Your article is very usefull; In Safari the error is
    Object [object INPUT] (result of expression document.form1.submit) does not allow calls.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  22. Coke says:

    I f$·%ing HATE JAVASCRIPT SO f$·%ing MUCH.

    So incompatible, so weird, you can’t trace the source of the problem quick. Sucks, Sucks and don’t stop sucking.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  23. chovy says:

    COKE – why don’t you use the javascript debugger in Firefox? just type “javascript:” in the address bar, then reload the page.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  24. chovy says:

    my french isn’t all that great….and your example got truncated COOLDEV, so I’m not sure what you’re trying to show.

    UA:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UA:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  25. junktown says:

    Thanks, I was starting to get frustrated :)

    UN:F [1.8.1_1037]
    Rating: 5.0/5 (1 vote cast)
    UN:F [1.8.1_1037]
    Rating: +1 (from 1 vote)
  26. r1tman says:

    I had a submit button named submit and that is what totally jacked my submit code. So all 1001 ways I coded it would never work because document.formname.submit was an object and I guess it found that before finding the submit function? Not sure why but I know what the problem was at least!

    – Rit

    UN:F [1.8.1_1037]
    Rating: 5.0/5 (1 vote cast)
    UN:F [1.8.1_1037]
    Rating: +1 (from 1 vote)
  27. Tony says:

    Thank you for this solution! I’ve been googling this issue for half an hour. Very helpful.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  28. Jess says:

    Thankyou! Ive been looking for hours for the reason why my javascript submit isnt working.

    This is it. Thanks

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  29. Steven says:

    Thanks a lot for providing this information.
    It solved my problem.

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  30. szako says:

    Thanks for this, i was going nuts. :-)

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  31. Ash says:

    Thanks! You saved my day!!!

    You rock !!!!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  32. DCE says:

    thank god i did a search on it…lol. saved my life! Thanks

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  33. Srinivas says:

    Hey!!

    Thanks a lot yaar!! I spent a lot of my time in getting know the error!! Finally got the answer from you!! thanks a lot!! :)

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  34. Meru says:

    Thank You So Much !!!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  35. Jaime Navarro says:

    THANK YOU !!!!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  36. Chris says:

    AWESOME ! Thank you. Just spent the last two hours trying to figure this one out!

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  37. ladokt says:

    THANKS SO MUCH

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)
  38. robert says:

    dang it, i copied some code and it had a button named submit, and i spent
    an hour trying to figure out why the heck my js was broken, thanks for the post

    UN:F [1.8.1_1037]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.1_1037]
    Rating: 0 (from 0 votes)

Leave a Reply