When is onSubmit fired?

Discussion in 'Javascript' started by Water Cooler v2, Apr 18, 2006.

  1. When does the onSubmit event occur? When does the JavaScript code we
    write in this event get executed?

    a. Before a page is posted to the server?
    b. After the page is posted back, if posted back to itself, and
    recieved from the server?
     
    Water Cooler v2, Apr 18, 2006
    #1
    1. Advertising

  2. Sorry. Please ignore this question.
     
    Water Cooler v2, Apr 18, 2006
    #2
    1. Advertising

  3. OK, I am confused. I asked this question because the JavaScript
    tutorial on w3schools says that onSubmit will cancel the submission if
    the code it executes returns a value false. To test, I did this and yet
    the page got posted to the target page successfully.


    <HTML>
    <SCRIPT>
    function decision()
    {
    return false;
    }
    </SCRIPT>

    <FORM name="frm" action="http://localhost/JavaScript/target.asp"
    method="POST">
    <INPUT type="text" name="txtWhatever" size="30" />
    <INPUT type="submit" onSubmit="return decision()"/>
    </FORM>
    </HTML>




    On target.asp, I just do:

    <HTML>
    <% Response.Write(Request.Form("txtWhatever")) %>
    </HTML>
     
    Water Cooler v2, Apr 18, 2006
    #3
  4. Water Cooler v2

    Lee Guest

    Water Cooler v2 said:
    >
    >OK, I am confused. I asked this question because the JavaScript
    >tutorial on w3schools says that onSubmit will cancel the submission if
    >the code it executes returns a value false. To test, I did this and yet
    >the page got posted to the target page successfully.


    ONSUBMIT is an attribute of the <form> element, not the submit button.


    <HTML>
    <head>
    <title>demo</title>
    <SCRIPT type="text/javascript">
    function decision()
    {
    return false;
    }
    </SCRIPT>
    </head>
    <body>
    <FORM name="frm"
    onsubmit="return decision()"
    action="http://localhost/JavaScript/target.asp"
    method="POST">
    <INPUT type="text" name="txtWhatever" size="30">
    <INPUT type="submit">
    </FORM>
    </body>
    </HTML>


    --
     
    Lee, Apr 18, 2006
    #4
  5. Water Cooler v2 wrote:
    > OK, I am confused. I asked this question because the JavaScript
    > tutorial on w3schools says that onSubmit will cancel the submission if
    > the code it executes returns a value false. To test, I did this and yet
    > the page got posted to the target page successfully.
    >
    > [snip]
    > <INPUT type="submit" onSubmit="return decision()"/>


    The function must be attached to the event of the FORM, not the submit
    button.

    <form [...] onsubmit="return decision()">
     
    Ronaldo Junior, Apr 18, 2006
    #5
  6. Thanks very much, Ronaldo.
     
    Water Cooler v2, Apr 18, 2006
    #6
  7. Thanks, Lee. I got that.
     
    Water Cooler v2, Apr 18, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U25vd2JhbmsgSmlt?=

    Form-level onSubmit handler

    =?Utf-8?B?U25vd2JhbmsgSmlt?=, Feb 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    415
    Peter Blum
    Feb 21, 2004
  2. Replies:
    3
    Views:
    1,148
    bruce barker
    Feb 25, 2004
  3. =?Utf-8?B?Q3Jpc3RpYW4gQ2FybHNzb24=?=

    Re: Add onSubmit To Form?

    =?Utf-8?B?Q3Jpc3RpYW4gQ2FybHNzb24=?=, May 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    683
    Steven Cheng[MSFT]
    May 27, 2004
  4. Joeyej
    Replies:
    0
    Views:
    8,065
    Joeyej
    Jun 4, 2004
  5. Mark Rae

    Re: onsubmit Event in aspx page.

    Mark Rae, Aug 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    414
    Mark Rae
    Aug 17, 2004
Loading...

Share This Page