How do I cancel a "submit"?

Discussion in 'Javascript' started by Martin, May 24, 2006.

  1. Martin

    Martin Guest

    I have a form with two submit buttons: <Save> and <Cancel>. When the
    user clicks on <Save>, I want to execute a validate function. When he
    clicks on <Cancel>, I want the form to submit without validation (I
    have server side scripting that handles the two different kinds of
    submits).

    In the "validate" function I have "return false" in the script (if the
    validation fails) but the form submits any way. How can I get this
    thing to not submit on a failed validation?
    Martin, May 24, 2006
    #1
    1. Advertising

  2. Martin wrote:


    > In the "validate" function I have "return false" in the script (if the
    > validation fails) but the form submits any way. How can I get this
    > thing to not submit on a failed validation?


    <input type="submit" name="Save" value="Save"
    onclick="return validate(this.form);">
    then let the validate function return true or false depending on whether
    the submission should be done or cancelled.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 24, 2006
    #2
    1. Advertising

  3. Martin

    RobG Guest

    Martin Honnen wrote:
    >
    >
    > Martin wrote:
    >
    >
    >> In the "validate" function I have "return false" in the script (if the
    >> validation fails) but the form submits any way. How can I get this
    >> thing to not submit on a failed validation?

    >
    > <input type="submit" name="Save" value="Save"
    > onclick="return validate(this.form);">
    > then let the validate function return true or false depending on whether
    > the submission should be done or cancelled.


    And if the form is submitted using the enter key (i.e. without clicking
    on either button), what should happen then?


    --
    Rob
    Group FAQ: <URL:http://www.jibbering.com/faq/>
    RobG, May 25, 2006
    #3
  4. Martin

    Guest

    Martin wrote:
    > I have a form with two submit buttons: <Save> and <Cancel>. When the
    > user clicks on <Save>, I want to execute a validate function. When he
    > clicks on <Cancel>, I want the form to submit without validation


    This sounds very shady. If the user clicks cancel they unknowingly
    believe you are honest and no one will see their information.

    I won't be clicking cancel anymore.

    Peter
    , May 25, 2006
    #4
  5. RobG wrote:

    > Martin Honnen wrote:
    >> Martin wrote:
    >>> In the "validate" function I have "return false" in the script (if the
    >>> validation fails) but the form submits any way. How can I get this
    >>> thing to not submit on a failed validation?

    >>
    >> <input type="submit" name="Save" value="Save"
    >> onclick="return validate(this.form);">
    >> then let the validate function return true or false depending on whether
    >> the submission should be done or cancelled.

    >
    > And if the form is submitted using the enter key (i.e. without clicking
    > on either button), what should happen then?


    Full ACK. I wished Martin would stop proposing this unreliable approach for
    he definitely should know better, also considering that we have discussed
    this ad nauseam here now, and reliable alternatives with `onsubmit' were
    presented.


    PointedEars
    --
    A man who works with his hands is a laborer; a man who works with his
    hands and his brain is a craftsman; but a man who works with his hands
    and his brain and his heart is an artist.
    -- Louis Nizer, lawyer (1902-1994)
    Thomas 'PointedEars' Lahn, May 26, 2006
    #5
    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. Joe C.

    Cancel submit?

    Joe C., Jul 15, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    4,547
    Steve C. Orr, MCSD
    Jul 15, 2003
  2. Iain
    Replies:
    2
    Views:
    540
  3. Mark
    Replies:
    1
    Views:
    1,649
  4. No_Spam

    Cancel Submit ASP.NET

    No_Spam, Feb 15, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    1,936
    Thomas Hansen
    Feb 15, 2007
  5. jbhopper

    button control and cancel submit

    jbhopper, Jan 27, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    205
    Ken Cox [Microsoft MVP]
    Jan 29, 2004
Loading...

Share This Page