Connecting Tech Pros Worldwide Forums | Help | Site Map

submit is not a function in FF but is in IE

yawnmoth
Guest
 
Posts: n/a
#1: Apr 18 '07
I'm trying to write a so-called bookmarklet for a specific web app and
am having some difficulty. One of the names of a specific forms
inputs is submit. As such, doing
document.getElementById('whatever').submit() doesn't work in FireFox
(it works in IE) because submit is now referring to the input field -
not to the function.

The usual "change the input's name" doesn't work because I don't have
any control over the site / web app. That's why I'm trying to write
the bookmarklet in the first place.

I've observed that document.getElementById('whatever').submit.click()
works in FireFox, but it doesn't work in IE. Now, I can do if
(document.getElementById('whatever').submit)) to decide which one I
want to do, but I'm wondering if there's a better way.

For example, maybe there's a way to get the input by the name? eg. a
getInputByName() function? Or maybe there's a way to execute the
submit() function without actually calling
getElementById('whatever').submit()?


Evertjan.
Guest
 
Posts: n/a
#2: Apr 18 '07

re: submit is not a function in FF but is in IE


yawnmoth wrote on 18 apr 2007 in comp.lang.javascript:
Quote:
I'm trying to write a so-called bookmarklet for a specific web app and
am having some difficulty. One of the names of a specific forms
inputs is submit. As such, doing
document.getElementById('whatever').submit() doesn't work in FireFox
(it works in IE) because submit is now referring to the input field -
not to the function.
>
The usual "change the input's name" doesn't work because I don't have
any control over the site / web app. That's why I'm trying to write
the bookmarklet in the first place.
>
I've observed that document.getElementById('whatever').submit.click()
works in FireFox, but it doesn't work in IE. Now, I can do if
(document.getElementById('whatever').submit)) to decide which one I
want to do, but I'm wondering if there's a better way.
>
For example, maybe there's a way to get the input by the name? eg. a
getInputByName() function? Or maybe there's a way to execute the
submit() function without actually calling
getElementById('whatever').submit()?
This does not "work" in IE or FF:

===========================================
<form>
<input name='submit' value=3>
</form>

<button onclick='document.forms[0].submit();'>
submit
</button>
===========================================

this does:

===========================================
<script type='text/javascript'>
function doit(x){
document.forms[0].innerHTML+='<input type=submit id=qqq>'
// or use the DOM version of above.
// if you use name=qqq it will be send in the querystring.
document.forms[0].elements['qqq'].click()
}
</script>

<body>
<form>
<input name='submit' value=3>
</form>

<button onclick='doit(this);'>
submit
</button>
===========================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Michael White
Guest
 
Posts: n/a
#3: Apr 18 '07

re: submit is not a function in FF but is in IE


yawnmoth wrote:
Quote:
I'm trying to write a so-called bookmarklet for a specific web app and
am having some difficulty. One of the names of a specific forms
inputs is submit. As such, doing
document.getElementById('whatever').submit() doesn't work in FireFox
(it works in IE) because submit is now referring to the input field -
not to the function.
Well, naming your submit button "submit" sometimes bites you in the arse.
Mick
Quote:
>
The usual "change the input's name" doesn't work because I don't have
any control over the site / web app. That's why I'm trying to write
the bookmarklet in the first place.
>
I've observed that document.getElementById('whatever').submit.click()
works in FireFox, but it doesn't work in IE. Now, I can do if
(document.getElementById('whatever').submit)) to decide which one I
want to do, but I'm wondering if there's a better way.
>
For example, maybe there's a way to get the input by the name? eg. a
getInputByName() function? Or maybe there's a way to execute the
submit() function without actually calling
getElementById('whatever').submit()?
>
wisestpotato
Guest
 
Posts: n/a
#4: Apr 18 '07

re: submit is not a function in FF but is in IE


On 18 Apr, 05:43, yawnmoth <terra1...@yahoo.comwrote:
Quote:
document.getElementById('whatever').submit() doesn't work in FireFox
(it works in IE) because submit is now referring to the input field -
not to the function.
>
An input element does not have a submit() method, so I'd be surprised
if what you are suggesting works in any browser. I think you must
actually mean to be calling the submit() method on the form element.
For example:

function submitForm() {
document.getElementById("myForm").submit();
}

<form id="myForm" action="blah" method="post">
<input type="text" name="blahblah">
</form>
<button type="button" onclick="submitForm">Submit Form</button>

The above should work.

Randy Webb
Guest
 
Posts: n/a
#5: Apr 18 '07

re: submit is not a function in FF but is in IE


wisestpotato said the following on 4/18/2007 9:35 AM:
Quote:
On 18 Apr, 05:43, yawnmoth <terra1...@yahoo.comwrote:
Quote:
>document.getElementById('whatever').submit() doesn't work in FireFox
>(it works in IE) because submit is now referring to the input field -
>not to the function.
>>
>
An input element does not have a submit() method, so I'd be surprised
if what you are suggesting works in any browser.
Then you should test it.
Quote:
I think you must actually mean to be calling the submit() method on the form element.
Yes, that is what he wants. But, he can't change the name in the HTML
itself. The solution is simple though.
Quote:
For example:
>
function submitForm() {
document.getElementById("myForm").submit();
}
>
<form id="myForm" action="blah" method="post">
<input type="text" name="blahblah">
</form>
<button type="button" onclick="submitForm">Submit Form</button>
>
The above should work.
Did you test that? onclick="submitForm()" might work better.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Randy Webb
Guest
 
Posts: n/a
#6: Apr 18 '07

re: submit is not a function in FF but is in IE


yawnmoth said the following on 4/18/2007 12:43 AM:
Quote:
I'm trying to write a so-called bookmarklet for a specific web app and
am having some difficulty. One of the names of a specific forms
inputs is submit. As such, doing
document.getElementById('whatever').submit() doesn't work in FireFox
(it works in IE) because submit is now referring to the input field -
not to the function.
>
The usual "change the input's name" doesn't work because I don't have
any control over the site / web app. That's why I'm trying to write
the bookmarklet in the first place.
Change it programatically by changing the .name property of the input.

document.getElementById('submit').name="newName"
document.getElementById('theFormID').submit()

No telling which name will get submitted to the server though for the input.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
wisestpotato
Guest
 
Posts: n/a
#7: Apr 19 '07

re: submit is not a function in FF but is in IE


On 18 Apr, 18:37, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
>
Quote:
An input element does not have a submit() method, so I'd be surprised
if what you are suggesting works in any browser.
>
Then you should test it.
>
Should I? Is it worth my time to track down copies of all the
available web browsers and test it? Can I not just reasonably
speculate that I would be surprised if it worked?
Quote:
>
Did you test that? onclick="submitForm()" might work better.
Beg your pardon, slip of the finger.

wp.

Closed Thread


Similar JavaScript / Ajax / DHTML bytes