My Javascript function doesn't work with FireFox

A

Amir

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
 
L

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

Tim Slattery

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?

Instead of

frm.action=action;

try:

document.getElementById(frm).action=action;

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

J. J. Cale

Tim Slattery said:
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

 
M

Michael Winter

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).
 
R

RobG

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

J. J. Cale

Michael Winter said:
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
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top