Submit() and onSubmit()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Benson-Manica

    Submit() and onSubmit()

    Why the heck doesn't document.aForm. submit() invoke aForm's onSubmit event
    handler?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
  • Grant Wagner

    #2
    Re: Submit() and onSubmit()

    Christopher Benson-Manica wrote:
    [color=blue]
    > Why the heck doesn't document.aForm. submit() invoke aForm's onSubmit event
    > handler?[/color]

    Because it doesn't.

    If you want it to, use Opera 7.0 or 7.1 which had a bug that caused that
    behaviour (it's been fixed in 7.21).

    The obviously solution is to call the validator code before calling submit():

    <a href="noJS.html " onclick="
    var f=document.form s['aForm'];
    if (validate(f)) f.submit();
    ">Submit</a>

    This would have the same effect as:

    <form ... onsubmit="retur n validate(this); ">
    <input type="submit" ... />
    </form>

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Gain technical skills through documentation and training, earn certifications and connect with the community


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • Christopher Benson-Manica

      #3
      Re: Submit() and onSubmit()

      Grant Wagner <gwagner@agrico reunited.com> spoke thus:
      [color=blue][color=green]
      >> Why the heck doesn't document.aForm. submit() invoke aForm's onSubmit event
      >> handler?[/color][/color]
      [color=blue]
      > Because it doesn't.[/color]

      I think I was misunderstood - I *know* it doesn't, I was curious about the
      rationale.
      [color=blue]
      > The obviously solution is to call the validator code before calling submit():[/color]

      I suppose, although I still wish my original plan were possible.

      --
      Christopher Benson-Manica | I *should* know what I'm talking about - if I
      ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Submit() and onSubmit()

        Christopher Benson-Manica wrote:
        [color=blue]
        > Grant Wagner <gwagner@agrico reunited.com> spoke thus:[color=green][color=darkred]
        >>> Why the heck doesn't document.aForm. submit() invoke aForm's onSubmit event
        >>> handler?[/color][/color]
        >[color=green]
        >> Because it doesn't.[/color]
        >
        > I think I was misunderstood - I *know* it doesn't, I was curious about the
        > rationale.[/color]

        The event does not fire here because the submit is initiated by the
        author/programmer, not by the user. But if you need to call the event
        handler explicitely, use

        document.forms['aForm'].onsubmit();

        in IE 6.0 and Mozilla/5.0, since it is implemented as an anonymous
        function there. (Note the use of the standards-compliant `forms' collection.)


        PointedEars

        Comment

        Working...