submit is not a function in FF but is in IE

Y

yawnmoth

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

Evertjan.

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>
===========================================
 
W

wisestpotato

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.
 
W

wisestpotato

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top