Connecting Tech Pros Worldwide Forums | Help | Site Map

My Javascript function doesn't work with FireFox

Amir
Guest
 
Posts: n/a
#1: Jul 23 '05
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


Lee
Guest
 
Posts: n/a
#2: Jul 23 '05

re: My Javascript function doesn't work with FireFox


Amir said:[color=blue]
>
>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?[/color]

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.

micha
Guest
 
Posts: n/a
#3: Jul 23 '05

re: My Javascript function doesn't work with FireFox


try using <a href="#" ...

micha

Tim Slattery
Guest
 
Posts: n/a
#4: Jul 23 '05

re: My Javascript function doesn't work with FireFox


"Amir" <webmaster@webfreeguide.com> wrote:
[color=blue]
>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?[/color]

Instead of

frm.action=action;

try:

document.getElementById(frm).action=action;

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

--
Tim Slattery
Slattery_T@bls.gov
J. J. Cale
Guest
 
Posts: n/a
#5: Jul 23 '05

re: My Javascript function doesn't work with FireFox



"Tim Slattery" <Slattery_T@bls.gov> wrote in message
news:5v520158qes4ine9bplqb9g3pnp3mq9epc@4ax.com...[color=blue]
> "Amir" <webmaster@webfreeguide.com> wrote:
>[color=green]
> >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?[/color]
>
> Instead of
>
> frm.action=action;
>
> try:
>
> document.getElementById(frm).action=action;
>
> where "frm" is the ID attribute of your form.[/color]

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

[color=blue]
> --
> Tim Slattery
> Slattery_T@bls.gov[/color]


Michael Winter
Guest
 
Posts: n/a
#6: Jul 23 '05

re: My Javascript function doesn't work with FireFox


J. J. Cale wrote:

[snip]
[color=blue]
> using the name attribute or index into the forms array seems to me
> the safest way to reference the form.[/color]

The forms collection. The object isn't actually an array (in an
ECMAScript sense).
[color=blue]
> IIRC the name att is a must in compliant browsers and is supported
> in all UA's.[/color]

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.
RobG
Guest
 
Posts: n/a
#7: Jul 23 '05

re: My Javascript function doesn't work with FireFox


J. J. Cale wrote:
[...][color=blue]
> 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.[/color]

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
J. J. Cale
Guest
 
Posts: n/a
#8: Jul 23 '05

re: My Javascript function doesn't work with FireFox



"Michael Winter" <m.winter@blueyonder.co.invalid> wrote in message
news:FzoMd.6214$8B3.2213@text.news.blueyonder.co.u k...[color=blue]
> J. J. Cale wrote:
>
> [snip]
>[color=green]
> > using the name attribute or index into the forms array seems to me
> > the safest way to reference the form.[/color]
>
> The forms collection. The object isn't actually an array (in an
> ECMAScript sense).
>[color=green]
> > IIRC the name att is a must in compliant browsers and is supported
> > in all UA's.[/color]
>
> 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).
>[/color]

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
[color=blue]
> --
> Michael Winter
> Replace ".invalid" with ".uk" to reply by e-mail.[/color]


Closed Thread