471,071 Members | 8,630 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

submit is not a function in FF but is in IE

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

Apr 18 '07 #1
6 11230
yawnmoth wrote on 18 apr 2007 in comp.lang.javascript:
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)
Apr 18 '07 #2
yawnmoth wrote:
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
>
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()?
Apr 18 '07 #3
On 18 Apr, 05:43, yawnmoth <terra1...@yahoo.comwrote:
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.

Apr 18 '07 #4
wisestpotato said the following on 4/18/2007 9:35 AM:
On 18 Apr, 05:43, yawnmoth <terra1...@yahoo.comwrote:
>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.
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.
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/
Apr 18 '07 #5
yawnmoth said the following on 4/18/2007 12:43 AM:
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/
Apr 18 '07 #6
On 18 Apr, 18:37, Randy Webb <HikksNotAtH...@aol.comwrote:
>
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?
>
Did you test that? onclick="submitForm()" might work better.
Beg your pardon, slip of the finger.

wp.

Apr 19 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by DB | last post: by
29 posts views Thread by Mic | last post: by
2 posts views Thread by Margaret Werdermann | last post: by
8 posts views Thread by horos | last post: by
5 posts views Thread by Navillus | last post: by
10 posts views Thread by ljlolel | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.