Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.getElementById("tweetform").submit is not a function?

Tags:

javascript

I'm using Firefox and I've been reading some forums claiming this doesn't work in firefox but it has been working for me for the last few days but has stopped working and I can not figure out why.

I make a AXAX POST Request using an IFrame. When I get the response I use this:

function startLoad(){
    $.get("update.php", function(data){
            if(data==''){
                startLoad();
            }
            else{
                document.getElementById("tweetform").submit();
            }
    });
}

However, from firebug, I get this:

document.getElementById("tweetform").submit is not a function
[Break on this error] document.getElementById("tweetform").submit();

I know submit exists, but what is going on?

like image 333
Abs Avatar asked Jul 08 '09 22:07

Abs


2 Answers

My guess would be that you have an element in the form that is called "submit" (possibly a <button> or <input type="submit">, and that ".submit" is retrieving a reference to that element, rather than the member function "submit()". If this is the case, try renaming that element to something else (e.g., "submit_button").

like image 175
Jason Musgrove Avatar answered Oct 31 '22 22:10

Jason Musgrove


Jason Musgrove explained the issue well.

You can use a native submit method of HTMLFormElement to work around a problem:

HTMLFormElement.prototype.submit.call($('#tweetform')[0]);
like image 24
ainokna Avatar answered Oct 31 '22 23:10

ainokna