FireFox submitting form twice

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NavinM
    New Member
    • Apr 2007
    • 3

    FireFox submitting form twice

    I have a couple of forms that are misbehaving in FireFox, but work fine in IE.

    when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the submission if there is an error.

    Sample (obviously not working code):
    [HTML] <html>
    <head>
    <script type="text/javascript">
    function Submit()
    {
    // do something, like form field validation before submitting
    return true;
    } else {
    return false; // do nothing, do not submit the form
    }
    }
    </script>
    </head>
    <body>
    <form name="myForm" action="form.cg i" onSubmit="retur n Submit()>
    Some form fields here<br/>
    <input type="submit" value="Submit" >
    </form>
    </body>
    </html>
    [/HTML]



    THE PROBLEM:
    In IE, the script performs as expected.

    In FireFox (tested in v2.0.0.3):
    * if the form validates correctly, it gets submitted twice:
    * if the form doesn't validate then nothing happen.

    Am I coding something wrong here? Why is FireFox submitting the form two times..
    Last edited by r035198x; Apr 24 '07, 10:10 AM. Reason: added code tags
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by NavinM
    I have a couple of forms that are misbehaving in FireFox, but work fine in IE.

    when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the submission if there is an error.

    Sample (obviously not working code):
    <html>
    <head>
    <script type="text/javascript">
    function Submit()
    {
    // do something, like form field validation before submitting
    return true;
    } else {
    return false; // do nothing, do not submit the form
    }
    }
    </script>
    </head>
    <body>
    <form name="myForm" action="form.cg i" onSubmit="retur n Submit()>
    Some form fields here<br/>
    <input type="submit" value="Submit" >
    </form>
    </body>
    </html>



    THE PROBLEM:
    In IE, the script performs as expected.

    In FireFox (tested in v2.0.0.3):
    * if the form validates correctly, it gets submitted twice:
    * if the form doesn't validate then nothing happen.

    Am I coding something wrong here? Why is FireFox submitting the form two times..
    I'm not a FireFox guru and am just trying my luck here,
    What happens if you call the function onClick of the submit button rather than onSubmit of the form?

    Comment

    • wgale025
      New Member
      • Feb 2007
      • 23

      #3
      try to change the function name

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by wgale025
        try to change the function name
        Of course. That should be it.

        Comment

        • NavinM
          New Member
          • Apr 2007
          • 3

          #5
          i tried to use onclick and the results are same.
          btw, onclick event will take care of only mouse click.
          but i need to make it generic,
          I want to use all three cases.
          a) submitting page by enter.
          b) submitting page by click
          c) submitting page by space when control is on submit button,

          i have tried with changing function but no luck.

          is there any other way, i can look on.

          Thanks

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by NavinM
            i tried to use onclick and the results are same.
            btw, onclick event will take care of only mouse click.
            but i need to make it generic,
            I want to use all three cases.
            a) submitting page by enter.
            b) submitting page by click
            c) submitting page by space when control is on submit button,

            i have tried with changing function but no luck.

            is there any other way, i can look on.

            Thanks
            Can you post the code you have now with the function name changed

            Comment

            • Grimm
              New Member
              • Apr 2007
              • 4

              #7
              Firefox automaticqally follows the submit standard function after an event has occured when using a submit button...if you change the button type to button instead of submit and change the function name it will work normally. Unfortunatley you loose some of the other funtionality options you want but give a little to get a little. Sorry

              Comment

              • NavinM
                New Member
                • Apr 2007
                • 3

                #8
                Originally posted by Grimm
                Firefox automaticqally follows the submit standard function after an event has occured when using a submit button...if you change the button type to button instead of submit and change the function name it will work normally. Unfortunatley you loose some of the other funtionality options you want but give a little to get a little. Sorry

                i found the solution afterall :)
                the page was being loaded with GET method and issue was -- " mismatching of character encoding" ( hence GET was being executed Twice )
                i used Central European ISO-8859-2 and everything is working fine

                refer the below link for more details ..


                Regards
                Navin

                Comment

                • Dashboard
                  New Member
                  • May 2007
                  • 6

                  #9
                  I'm still getting the problem. I've checked and set the charset encoding on the response header but with no luck [UTF-8]. FF still issues a Post and then a Get. Could someone please detail out how the solution is working for them.

                  One thing to note is that I use javascript to submit my form onchange of a text field. That should not make a difference.

                  The page meta tags -
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                  <meta http-equiv="Pragma" content="nocach e"/>
                  <meta http-equiv="Cache-Control" content="privat e"/>
                  <meta http-equiv="Cache-Control" content="proxy-revalidate"/>

                  Note I tried with the following as well -
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                  <meta http-equiv="Pragma" content="no-cache,no-store,max-age=0"/>
                  <meta http-equiv="Cache-Control" content="nocach e"/>

                  In my servlet I set the following

                  response.setHea der("Pragma", "No-cache");
                  response.setHea der("Cache-Control", "no-cache,no-store,max-age=0");
                  response.setHea der("Content-Type", "text/html; charset=UTF-8");
                  response.setDat eHeader("Expire s", 1);


                  Am I doing something wrong here?

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by Dashboard
                    I'm still getting the problem. I've checked and set the charset encoding on the response header but with no luck [UTF-8]. FF still issues a Post and then a Get. Could someone please detail out how the solution is working for them.

                    One thing to note is that I use javascript to submit my form onchange of a text field. That should not make a difference.

                    The page meta tags -
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                    <meta http-equiv="Pragma" content="nocach e"/>
                    <meta http-equiv="Cache-Control" content="privat e"/>
                    <meta http-equiv="Cache-Control" content="proxy-revalidate"/>

                    Note I tried with the following as well -
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                    <meta http-equiv="Pragma" content="no-cache,no-store,max-age=0"/>
                    <meta http-equiv="Cache-Control" content="nocach e"/>

                    In my servlet I set the following

                    response.setHea der("Pragma", "No-cache");
                    response.setHea der("Cache-Control", "no-cache,no-store,max-age=0");
                    response.setHea der("Content-Type", "text/html; charset=UTF-8");
                    response.setDat eHeader("Expire s", 1);


                    Am I doing something wrong here?
                    What's the character encoding in your browser?

                    Comment

                    • Dashboard
                      New Member
                      • May 2007
                      • 6

                      #11
                      Originally posted by acoder
                      What's the character encoding in your browser?
                      The browser encoding is - UTF-8
                      I've narrowed it down to my javascript stmt.
                      Code:
                      function mysubmit(){
                      alert('1');
                      document.forms[0].submit();
                      alert('2');
                      }
                      alert('1') is displayed - No request yet submitted, Press OK, alert 2 is displayed. 2 requests submitted.

                      Comment

                      • pbmods
                        Recognized Expert Expert
                        • Apr 2007
                        • 5821

                        #12
                        Change the action of your form:

                        [HTML]
                        <form ... action="mySubmi t();">
                        [/HTML]

                        And then instead of returning true in mySubmit:

                        Code:
                        document.forms[0].action = 'thepage.php';
                        document.forms[0].submit();

                        Comment

                        • Dashboard
                          New Member
                          • May 2007
                          • 6

                          #13
                          I tried to make the form action="" and set the action explicitly in the js, returned true from it. Still doesn't work.
                          My requirement is that the js should be called onchange of a text field, hence I've made the form action as an empty string

                          Comment

                          • pbmods
                            Recognized Expert Expert
                            • Apr 2007
                            • 5821

                            #14
                            Originally posted by Dashboard
                            I tried to make the form action="" and set the action explicitly in the js, returned true from it. Still doesn't work.
                            My requirement is that the js should be called onchange of a text field, hence I've made the form action as an empty string
                            If the form's action is an empty string, then it will use the current page as the action. Instead, do this:

                            Code:
                            form.action = 'void('');';

                            Comment

                            • Dashboard
                              New Member
                              • May 2007
                              • 6

                              #15
                              Originally posted by pbmods
                              If the form's action is an empty string, then it will use the current page as the action. Instead, do this:

                              Code:
                              form.action = 'void('');';

                              That doesn't help either

                              Comment

                              Working...