By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

My Javascript function doesn't work with FireFox

P: n/a
I have a common Jscript function in my "common.js" file
It is:

function submitForm(frm,action){
frm.action=action;
frm.submit();
return(false)
}
To submit my form fields to any other page I

Use this function like this

<A href="" onclick="return submitForm(myFormName,'\mydir\mypage.asp')">
sample link</A>

This function works completely in IE 5+ but it doesn't work in
FireFox

What is the problem?

http://www.webfreeguide.com

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Lee
Amir said:

I have a common Jscript function in my "common.js" file
It is:

function submitForm(frm,action){
frm.action=action;
frm.submit();
return(false)
}
To submit my form fields to any other page I

Use this function like this

<A href="" onclick="return submitForm(myFormName,'\mydir\mypage.asp')">
sample link</A>

This function works completely in IE 5+ but it doesn't work in
FireFox

What is the problem?


Decent browsers don't let you refer to a form simply by its name.
At the very least, you need something like:

onclick="return submitForm(document.myFormName,'\mydir\mypage.asp' )"

You should also have some reasonable value for the HREF attribute,
such as the URL of a page explaining why you don't want to allow
people with Javascript disabled to be able to submit your form.

Jul 23 '05 #2

P: n/a
try using <a href="#" ...

micha

Jul 23 '05 #3

P: n/a
"Amir" <we*******@webfreeguide.com> wrote:
I have a common Jscript function in my "common.js" file
It is:

function submitForm(frm,action){
frm.action=action;
frm.submit();
return(false)
}
To submit my form fields to any other page I

Use this function like this

<A href="" onclick="return submitForm(myFormName,'\mydir\mypage.asp')">
sample link</A>

This function works completely in IE 5+ but it doesn't work in
FireFox

What is the problem?


Instead of

frm.action=action;

try:

document.getElementById(frm).action=action;

where "frm" is the ID attribute of your form.

--
Tim Slattery
Sl********@bls.gov
Jul 23 '05 #4

P: n/a

"Tim Slattery" <Sl********@bls.gov> wrote in message
news:5v********************************@4ax.com...
"Amir" <we*******@webfreeguide.com> wrote:
I have a common Jscript function in my "common.js" file
It is:

function submitForm(frm,action){
frm.action=action;
frm.submit();
return(false)
}
To submit my form fields to any other page I

Use this function like this

<A href="" onclick="return submitForm(myFormName,'\mydir\mypage.asp')">
sample link</A>

This function works completely in IE 5+ but it doesn't work in
FireFox

What is the problem?
Instead of

frm.action=action;

try:

document.getElementById(frm).action=action;

where "frm" is the ID attribute of your form.


using the name attribute or index into the forms array seems to me the
safest way to reference the form.
IIRC the name att is a must in compliant browsers and is supported in all
UA's.
document.forms[0].etc
document.forms['idAtt'].etc

Jimbo

--
Tim Slattery
Sl********@bls.gov

Jul 23 '05 #5

P: n/a
J. J. Cale wrote:

[snip]
using the name attribute or index into the forms array seems to me
the safest way to reference the form.
The forms collection. The object isn't actually an array (in an
ECMAScript sense).
IIRC the name att is a must in compliant browsers and is supported
in all UA's.


Only in that it is the most used method. The preferred approach is to
use the id attribute; the name attribute has been relegated to a state
of backwards compatibility. In theory, this means a future version of
HTML can deprecate the name attribute. In fact, this has happened in
XHTML 1.0 - the name attribute isn't defined in the Strict DTD.

FORM elements should be "labeled" using the id attribute. If
compatibility with ancient browsers like NN4 is desired, add the name
attribute as well. This also applies to images.

Whatever approach you take, it is still preferable to use the forms
(or images) collections as these are well supported and will accept
both name and id attribute values.

Mike
Be aware that this discussion does not extend to form controls (INPUT,
etc).

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6

P: n/a
J. J. Cale wrote:
[...]
using the name attribute or index into the forms array seems to me the
safest way to reference the form.
IIRC the name att is a must in compliant browsers and is supported in all
UA's.


Hmmm. In regard to the name attribute of forms, the w3c HTML
4.01 spec says:

"name = cdata [CI]
This attribute names the element so that it may be referred to
from style sheets or scripts. Note. This attribute has been
included for backwards compatibility. Applications should use
the id attribute to identify elements."

<URL:http://www.w3.org/TR/html4/interact/forms.html#adef-name-FORM>

So whilst the name attribute of a form continues to be supported
(and I think your opinion regarding its use is correct), working
solely from the spec may result in a different point of view.

--
Rob
Jul 23 '05 #7

P: n/a

"Michael Winter" <m.******@blueyonder.co.invalid> wrote in message
news:Fz*****************@text.news.blueyonder.co.u k...
J. J. Cale wrote:

[snip]
using the name attribute or index into the forms array seems to me
the safest way to reference the form.
The forms collection. The object isn't actually an array (in an
ECMAScript sense).
IIRC the name att is a must in compliant browsers and is supported
in all UA's.


Only in that it is the most used method. The preferred approach is to
use the id attribute; the name attribute has been relegated to a state
of backwards compatibility. In theory, this means a future version of
HTML can deprecate the name attribute. In fact, this has happened in
XHTML 1.0 - the name attribute isn't defined in the Strict DTD.

FORM elements should be "labeled" using the id attribute. If
compatibility with ancient browsers like NN4 is desired, add the name
attribute as well. This also applies to images.

Whatever approach you take, it is still preferable to use the forms
(or images) collections as these are well supported and will accept
both name and id attribute values.

Mike
Be aware that this discussion does not extend to form controls (INPUT,
etc).


Thanks guys. I'm over my head here. Is the name attribute necessary in a
control?
I don't keep an efficient archive but I recall a situation where I tried to
reference
an input in a form and came up empty. I don't remember the error msg but it
was
resolved by adding the name attribute which conclusion I got from one of the
specs.
Again I'm sorry for my poor archiving. I really tried to find the example
but it's buried
somewhere on my hard disk. Hope I haven't added to the confusion. Thanks for
correcting me.
Jimbo
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.