Submitting a form and onSubmit Validation?

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

    Submitting a form and onSubmit Validation?

    I just noticed that if I use a "submit" button the "onSubmit" function call
    will be invoked. But if I use a button to call some other javascript and at
    the end of that javascrip I do something like "form.submi t()" the "onSubmit"
    function call will NOT be invoked. I thought that was wierd. Can anyone
    shed some light? Here's a small example:

    <script type="text/javascript">
    function subform()
    {
    document.frm1.s ubmit();
    }
    function checkform()
    {
    alert('checking form');
    return true;
    }
    </script>
    </head>

    <body>
    <form name="frm1" method="post" action="" onSubmit="retur n checkform();">
    <input type="text" name="txtname"> <br>
    <input type="submit" name="btnsubmit " value="submit"> <br>
    <input type="button" name="btn1" value="go" onClick="subfor m();">
    </form>
    </body>

    -Bruce Duncan



  • Peter O'Reilly

    #2
    Re: Submitting a form and onSubmit Validation?

    If your code is explicitly calling the submit method, then it should be able
    to do form validation work before calling it.

    The logical conclusion is to change your <input type="submit" to <input
    type="button" thereby having one entry point for doing your onsubmit/forma
    validation work.
    --
    Peter O'Reilly


    Comment

    • Bruce Duncan

      #3
      Re: Submitting a form and onSubmit Validation?

      "Peter O'Reilly" <Peter_OReilly@ timeinc.com!N!O !.S!P!AM!> wrote in message
      news:cfbdc9$fqu $1@inntp-m1.news.aol.com ...[color=blue]
      > If your code is explicitly calling the submit method, then it should be[/color]
      able[color=blue]
      > to do form validation work before calling it.
      >
      > The logical conclusion is to change your <input type="submit" to <input
      > type="button" thereby having one entry point for doing your onsubmit/forma
      > validation work.
      > --
      > Peter O'Reilly
      >[/color]
      I thought doing form.submit() was just the same as "clicking a submit
      button?" I guess not. Your conclusions are correct and I would do
      something like that if I were working on a problem. I just happen to notice
      this "feature" and thought it was wierd. Thanks for your input.

      -Bruce Duncan



      Comment

      • Peter O'Reilly

        #4
        Re: Submitting a form and onSubmit Validation?

        > I just happen to notice this "feature" and thought it was wierd. Thanks
        for your input.

        I understand your comments full well. Keep in mind though that this
        behavior is consistent across web browsers and
        is part of the Netscape language specification for JavaScript, if I'm not
        mistaken. If not JavaScript then the ECMA specs
        (I'm admittedly too lazy to re-look up) and most definitely in the
        "JavaScript : The definitive guide" book (which I highly recommend).
        --
        Peter O'Reilly


        Comment

        • Bruce Duncan

          #5
          Re: Submitting a form and onSubmit Validation?

          "Peter O'Reilly" <Peter_OReilly@ timeinc.com!N!O !.S!P!AM!> wrote in message
          news:cfdcsh$ika $1@inntp-m1.news.aol.com ...[color=blue][color=green]
          > > I just happen to notice this "feature" and thought it was wierd.[/color][/color]
          Thanks[color=blue]
          > for your input.
          >
          > I understand your comments full well. Keep in mind though that this
          > behavior is consistent across web browsers and
          > is part of the Netscape language specification for JavaScript, if I'm not
          > mistaken. If not JavaScript then the ECMA specs
          > (I'm admittedly too lazy to re-look up) and most definitely in the
          > "JavaScript : The definitive guide" book (which I highly recommend).
          > --
          > Peter O'Reilly
          >[/color]

          How right you are Peter...
          Page 573...Javascrip t the definitive guide...4th ed

          ....had only I read this first...

          -Bruce Duncan



          Comment

          Working...