Loading ...
Sorry, an error occurred while loading the content.

Prevent form default action in case of invalid form data on Firefox

Expand Messages
  • shadeoh
    Hi All: Can anyone send me a simple complete example of how to prevent the execution of a form s default action in the case of invalid form data? My form works
    Message 1 of 4 , Feb 17, 2009
    • 0 Attachment
      Hi All:

      Can anyone send me a simple complete example of how to prevent the
      execution of a form's default action in the case of invalid form data?
      My form works correctly in Internet Explorer 6, but not in Firefox 3
      or other compliant browsers. The form, the form validate, and the
      default action are all written in javascript. There are no syntax
      errors. Check out my site at goalaccess.com with Firefox and you will
      see the problem. Try to submit the form with no data. The validation
      function correctly displays an error message, but when the 'OK' button
      is pressed the default action will be invoked, instead of returning to
      the form.

      Many Thanks:
      Shadeoh
    • Dermot
      ... Complete example no. But try a combination of onsubmit and return; Dp.
      Message 2 of 4 , Feb 17, 2009
      • 0 Attachment
        2009/2/17 shadeoh <healthyhiker2005@...>:
        > Hi All:
        >
        > Can anyone send me a simple complete example of how to prevent the
        > execution of a form's default action in the case of invalid form data?
        > My form works correctly in Internet Explorer 6, but not in Firefox 3
        > or other compliant browsers. The form, the form validate, and the
        > default action are all written in javascript. There are no syntax
        > errors. Check out my site at goalaccess.com with Firefox and you will
        > see the problem. Try to submit the form with no data. The validation
        > function correctly displays an error message, but when the 'OK' button
        > is pressed the default action will be invoked, instead of returning to
        > the form.
        >
        > Many Thanks:
        > Shadeoh

        Complete example no. But try a combination of onsubmit and return;
        Dp.
      • David Smart
        Please show your code. Regards, Dave S ... From: shadeoh To: Sent: Tuesday, February 17,
        Message 3 of 4 , Feb 17, 2009
        • 0 Attachment
          Please show your code.

          Regards, Dave S

          ----- Original Message -----
          From: "shadeoh" <healthyhiker2005@...>
          To: <JavaScript_Official@yahoogroups.com>
          Sent: Tuesday, February 17, 2009 7:38 PM
          Subject: [JavaScript] Prevent form default action in case of invalid form
          data on Firefox


          > Hi All:
          >
          > Can anyone send me a simple complete example of how to prevent the
          > execution of a form's default action in the case of invalid form data?
          > My form works correctly in Internet Explorer 6, but not in Firefox 3
          > or other compliant browsers. The form, the form validate, and the
          > default action are all written in javascript. There are no syntax
          > errors. Check out my site at goalaccess.com with Firefox and you will
          > see the problem. Try to submit the form with no data. The validation
          > function correctly displays an error message, but when the 'OK' button
          > is pressed the default action will be invoked, instead of returning to
          > the form.
          >
          > Many Thanks:
          > Shadeoh
          >
          >
          >
          > ------------------------------------
          >
          > Visit http://aiaiai.com for more groups to joinYahoo! Groups Links
          >
          >
          >
          >
        • Tim Sabin
          Hi, When you sense a button, call the JavaScript onSubmit handler in the form tag. This returns either true or false; true invokes the action, false
          Message 4 of 4 , Feb 17, 2009
          • 0 Attachment
            Hi,

            When you sense a <submit> button, call the JavaScript onSubmit handler
            in the form tag. This returns either true or false; true invokes the
            action, false aborts the submit.

            <script type="text/javascript">
            function something () {
            if (somethingElse) {
            return true;
            } else {
            return false;
            }
            }
            </script>
            ...
            <form name="myForm" onSubmit="return something ();">
            ...
            </form>

            --Tim Sabin


            > Hi All:
            >
            > Can anyone send me a simple complete example of how to prevent the
            > execution of a form's default action in the case of invalid form
            data?
            > My form works correctly in Internet Explorer 6, but not in Firefox 3
            > or other compliant browsers. The form, the form validate, and the
            > default action are all written in javascript. There are no syntax
            > errors. Check out my site at goalaccess.com with Firefox and you will
            > see the problem. Try to submit the form with no data. The validation
            > function correctly displays an error message, but when the 'OK'
            button
            > is pressed the default action will be invoked, instead of returning
            to
            > the form.
            >
            > Many Thanks:
            > Shadeoh
            >
            >
            >
            > ------------------------------------
            >
            > Visit http://aiaiai.com for more groups to joinYahoo! Groups Links
            >
            >
            >
            >

            --Tim Sabin
          Your message has been successfully submitted and would be delivered to recipients shortly.