TypeError: '[object HTMLInputElement]' is not a function (evaluating 'elem[ type ]()') in jQuery form.submit()
Asked Answered
V

3

11

Has never run into this issue? I'm getting this error in the latest release of jQuery. I tried with version 1.6.2 and there is no issue.

TypeError: '[object HTMLInputElement]' is not a function (evaluating 'elem[ type ]()')

line 3175

Has anything changed that we should be aware of?

Thanks, Jack

Ventris answered 29/12, 2011 at 20:17 Comment(4)
can you show the relevant code?Demography
Looks more like you are passing a wrong argument somewhere.Nuke
Maybe try $(form).submit().Catron
It's your selector. jQuery objects are different than DOM Object. I can see you're trying to apply a jquery function to a DOM element. Do this: $(yourelement).submit(... instead of yourelement.subimit(...Jacobjacoba
E
36

This usually happens if any of your input tag's name is submit. For example,

<form id="frm">
    <input type="submit" name="submit" value="Post" />
</form>

On the above code, document.getElementById("frm").submit represents the input element. When you apply () to submit It shows this error.

Escamilla answered 29/12, 2011 at 20:28 Comment(7)
Thanks Shiplu. That was it. I guess I have to be more careful about what name to use when using jQuery.Ventris
@juminoz: That's not related to jQuery, it is a general JavaScript/DOM/scope problem.Nuke
@FelixKling That may be true, but since I didn't see the same issue in version 1.6.2, I assumed that something might have changed.Ventris
This is mentioned in the jQuery docs, but the wording is rather vague: 'Name conflicts can cause confusing failures.' So good thing there's something like the SO community for practical answers to practical problems.Ionian
Solved something for me, too. Good rule I will now follow is don't use IDs that are the same as the input type.Bossuet
This was driving me crazy all day $('#form").submit() and $("#form").trigger('submit') nothing would work, my submit button was named submit...changed it and now working, thanks!Candidacandidacy
This answer is very good (saved me a lot of time!) but does anyone know the reason why jQuery won't allow name="submit"? It would be good to know that.Teston
H
7

I have found that this error will occur when using the onclick attribute to call a JavaScript function with the same name as either the id or name attributes on an input element:

<input id='foo' name='fooName' onclick='foo();'> <!-- BAD: id matches function -->

<input id='fooId' name='foo' onclick='foo();'> <!-- BAD: name matches function -->

<input id='fooId' name='fooName' onclick='foo();'> <!-- WORKS! -->

This behavior occurs irrespective of input type.

Honorific answered 30/11, 2014 at 20:40 Comment(2)
This is exactly what was causing the error for me. I had a checkbox setup as such: <input type="checkbox" id="toggleCheck" name="toggleCheck" onClick="toggleCheck();"> It worked properly once I renamed the "name" and "id" tags: <input type="checkbox" id="toggleCheckbox" name="toggleCheckbox" onClick="toggleCheck();">Barquentine
took me ages to found your solution because nobody wrote a real example with ids and names.. otherwise these guys would realize, that matching names cause this error. thanks a lot!Accelerate
T
3

I hade a similar issue with safari recently on a bit of javascript to submit a form. Turned out to be due to the submit input element having the name="submit", which was conflicting causing it to return it as not being a function.

Thrifty answered 9/5, 2012 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.