PDA

View Full Version : FireFox: submitting forms with Javascript



mattster
08-11-2005, 11:17 AM
I have various forms (using ASP as the backend) which simply will not submit with FireFox when using a "button" element with onclick="document.myform.submit();".

Does anyone know what i am doing wrong or if there is some other way you are meant to code it for FireFox?

All works perfectly in IE.

I can post more code if you need it.

:confused:

Cheers!

Twey
08-11-2005, 12:27 PM
Try giving it an ID and submitting with document.getElementById("id").submit()
or document.forms[0].submit

mattster
08-17-2005, 12:19 PM
A late reply i know but i have been away. Anyway, back to the problem. Unfortunately this still does not work, with either method.

Here is some of the code:


<form name="s1_2" id="s1_2" action="s1_2.asp" method="post">
<input type="hidden" name="a" id="a" value="U">

<input type="button" name="Back" value="<< Back" onclick="document.s1_2.a.value='P';document.s1_2.submit();" style="width:80px" />&nbsp;&nbsp;&nbsp;
<input type="submit" name="Next" value="Next >>" style="width:80px" />

</form>
As said before this all works fine in IE and even when i change it to:
document.getElementById('a').value='P';
document.getElementById('s1_2').submit();

still nothing happens in FireFox - just nothing!

I just don't understand - how can one then use an image or something to submit forms etc in FF?

Please can someone shed some light on this for me?

Many thanks.

PS the "a" field is used so the asp page knows whether to go forwards or back through a sequence of pages... hence why i need to be able to change that as well - not just submitting the form, but it is all the same problem.

mwinter
08-17-2005, 02:05 PM
[...]

<form name="s1_2" id="s1_2" action="s1_2.asp" method="post">
<input type="hidden" name="a" id="a" value="U">

[...]
[...]

PS the "a" field is used so the asp page knows whether to go forwards or back through a sequence of pages... hence why i need to be able to change that as well - not just submitting the form [...].You don't need to do that at all. Buttons can be successful controls as well as text boxes, and the like. Name both buttons something sensible, like 'direction', and then check the value on the server. You can then omit the hidden field, probably the name and id attributes on your form element as well, and this thing becomes a non-issue.

As for the original problem, I can't replicate it, so I can't suggest a reason, or a solution. If you want either, post a URL to a small test page that demonstrates the issue.

Mike

mattster
08-18-2005, 12:19 PM
Hmm - i feel like a right fool! I had stupidly disabled Javascript in FF a while back whilst testing and forgot to turn it back on.

It works and always has done!

Cheers for your help and sorry to have wasted your time.