RSS
 

Javascript Error: submit is not a function

03 Aug

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:


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:

Login
VN:F [1.9.3_1094]
Rating: 9.0/10 (22 votes cast)
VN:F [1.9.3_1094]
Rating: +11 (from 11 votes)
Javascript Error: submit is not a function, 9.0 out of 10 based on 22 ratings
Retweet
 
 
  1. T Grove

    April 25, 2006 at 9:31 pm

    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???

    VA:F [1.9.3_1094]
    Rating: 3.5/5 (4 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 2 votes)
     
  2. haval

    May 1, 2006 at 5:59 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  3. The Swede

    May 5, 2006 at 1:26 am

    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…

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  4. jeconais

    May 14, 2006 at 12:08 pm

    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.

    VA:F [1.9.3_1094]
    Rating: 5.0/5 (2 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  5. Steve

    May 14, 2006 at 11:58 pm

    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.

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  6. Wee Keat

    July 12, 2006 at 1:24 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  7. Kevin

    July 16, 2006 at 12:34 pm

    YOU SOLVED MY PROBLEM!

    You rock!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  8. chovy

    July 16, 2006 at 3:47 pm

    You’re welcome!

    VN:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  9. Anonymous

    July 19, 2006 at 10:51 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  10. Mike

    September 8, 2006 at 3:16 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  11. Ryan

    September 18, 2006 at 11:08 am

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

    Ryan

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  12. Ian

    October 1, 2006 at 5:24 am

    I loooooooooooooooooooooooooooooooove you!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  13. Avinash

    October 2, 2006 at 12:35 pm

    gr888888888888 work dude………!!!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  14. crazy

    October 3, 2006 at 1:55 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  15. moty66

    October 12, 2006 at 5:55 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  16. Anthony Ettinger

    October 12, 2006 at 11:07 am

    I know – first thing I should’ve checked when I got the unexplainable was “reserved words”.

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  17. Ian Good

    October 19, 2006 at 9:16 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  18. jon

    October 27, 2006 at 3:46 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  19. Marko Tulio corona Pacheco

    November 7, 2006 at 3:39 pm

    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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  20. TracyTrace

    November 15, 2006 at 10:17 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  21. Oscar González

    November 23, 2006 at 10:09 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  22. Coke

    November 24, 2006 at 4:00 am

    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.

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: -1 (from 1 vote)
     
  23. chovy

    November 24, 2006 at 1:39 pm

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

    VN:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.3_1094]
    Rating: -1 (from 1 vote)
     
  24. chovy

    February 2, 2007 at 10:36 am

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

    VN:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  25. junktown

    May 9, 2007 at 11:05 am

    Thanks, I was starting to get frustrated :)

    VN:F [1.9.3_1094]
    Rating: 5.0/5 (1 vote cast)
    VN:F [1.9.3_1094]
    Rating: +1 (from 1 vote)
     
  26. r1tman

    May 29, 2007 at 11:00 pm

    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

    VN:F [1.9.3_1094]
    Rating: 5.0/5 (1 vote cast)
    VN:F [1.9.3_1094]
    Rating: +1 (from 1 vote)
     
  27. Tony

    August 16, 2007 at 1:36 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  28. Jess

    September 26, 2007 at 3:47 pm

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

    This is it. Thanks

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  29. Steven

    October 26, 2007 at 2:27 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  30. szako

    April 11, 2008 at 2:34 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  31. Ash

    November 20, 2008 at 11:05 am

    Thanks! You saved my day!!!

    You rock !!!!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  32. DCE

    January 27, 2009 at 8:29 am

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  33. Srinivas

    August 4, 2009 at 7:56 am

    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!! :)

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  34. Meru

    November 11, 2009 at 5:42 am

    Thank You So Much !!!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  35. Jaime Navarro

    November 19, 2009 at 12:31 pm

    THANK YOU !!!!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  36. Chris

    November 19, 2009 at 11:04 pm

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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  37. ladokt

    November 23, 2009 at 12:47 am

    THANKS SO MUCH

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  38. robert

    January 29, 2010 at 12:42 pm

    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

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  39. Jonatan

    February 18, 2010 at 12:12 pm

    Thanks men!!!!!!!!!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  40. Marvelade

    March 25, 2010 at 7:15 am

    It’s not only a matter of reserved words, it’s also a matter of element naming conflicts that you do yourself.

    Found out this after a good half hour of scratching my head:

    will trigger a JS error “toggle_all is not a function” BECAUSE toggle_all is the name of the input element.

    this code works:

    because I set the name of the input element to something else than the function name.

    Hope this saves somebody some time.

    best regards,
    Marvelade

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  41. Marvelade

    March 25, 2010 at 7:17 am

    HTML was stripped out of my previous message.

    I’ll try to use HTML equivs:

    < input type=”checkbox” name=”toggle_all” onclick=”toggle_all();” >

    < input type=”checkbox” name=”toggle_everything” onclick=”toggle_all();” >

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  42. Ben

    April 28, 2010 at 7:24 am

    OMG THANK YOU SO MUCH! I searched high and low on Google and I finally found this article that saved my insanity. THANK YOU!

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  43. Shailesh Prajpati

    June 25, 2010 at 9:21 am

    I will just say about this article. – “Amazzing…” . I am PHP Web Developer and this article solved my problem of javascript….
    Thanks Buddy

    VA:F [1.9.3_1094]
    Rating: 4.0/5 (1 vote cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  44. saeed

    June 30, 2010 at 4:15 am

    I am very much thankful to you for your lovely and informative post. It saved alot of my precious time..thank you ..

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  45. Eduardo Rodrigues

    July 8, 2010 at 12:21 pm

    Man,

    thank you sooooo much!!!!!!

    I´ve been over this for hours!!!
    In debug, it would show the form as a form, with the submit method and all… but, error on the call. There was nothing poiting that the submit was being misplaced with the form button that had the same name.

    You were a NINJA to find this out!

    Thank you!!!!!!!!!!

    VA:F [1.9.3_1094]
    Rating: 5.0/5 (1 vote cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
     
  46. chovy

    July 8, 2010 at 1:01 pm

    Thanks, glad I could help.

    VN:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.3_1094]
    Rating: 0 (from 0 votes)