My Javascript function doesn't work with FireFox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amir

    #1

    My Javascript function doesn't work with FireFox

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

    function submitForm(frm, action){
    frm.action=acti on;
    frm.submit();
    return(false)
    }


    To submit my form fields to any other page I

    Use this function like this

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

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

    What is the problem?



  • Lee

    #2
    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=act ion;
    >frm.submit() ;
    >return(false )
    >}
    >
    >
    >To submit my form fields to any other page I
    >
    >Use this function like this
    >
    ><A href="" onclick="return submitForm(myFo rmName,'\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(docu ment.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.

    Comment

    • micha

      #3
      Re: My Javascript function doesn't work with FireFox

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

      micha

      Comment

      • Tim Slattery

        #4
        Re: My Javascript function doesn't work with FireFox

        "Amir" <webmaster@webf reeguide.com> wrote:
        [color=blue]
        >I have a common Jscript function in my "common.js" file
        >It is:
        >
        >function submitForm(frm, action){
        >frm.action=act ion;
        >frm.submit() ;
        >return(false )
        >}
        >
        >
        >To submit my form fields to any other page I
        >
        >Use this function like this
        >
        ><A href="" onclick="return submitForm(myFo rmName,'\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=acti on;

        try:

        document.getEle mentById(frm).a ction=action;

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

        --
        Tim Slattery
        Slattery_T@bls. gov

        Comment

        • J. J. Cale

          #5
          Re: My Javascript function doesn't work with FireFox


          "Tim Slattery" <Slattery_T@bls .gov> wrote in message
          news:5v520158qe s4ine9bplqb9g3p np3mq9epc@4ax.c om...[color=blue]
          > "Amir" <webmaster@webf reeguide.com> wrote:
          >[color=green]
          > >I have a common Jscript function in my "common.js" file
          > >It is:
          > >
          > >function submitForm(frm, action){
          > >frm.action=act ion;
          > >frm.submit() ;
          > >return(false )
          > >}
          > >
          > >
          > >To submit my form fields to any other page I
          > >
          > >Use this function like this
          > >
          > ><A href="" onclick="return submitForm(myFo rmName,'\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=acti on;
          >
          > try:
          >
          > document.getEle mentById(frm).a ction=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]


          Comment

          • Michael Winter

            #6
            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.

            Comment

            • RobG

              #7
              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

              Comment

              • J. J. Cale

                #8
                Re: My Javascript function doesn't work with FireFox


                "Michael Winter" <m.winter@bluey onder.co.invali d> wrote in message
                news:FzoMd.6214 $8B3.2213@text. news.blueyonder .co.uk...[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]


                Comment

                Working...