Form validation - prevent certain buttons firing

Discussion in 'Javascript' started by Nick Bell, May 27, 2005.

  1. Nick Bell

    Nick Bell Guest

    I have a general form validation question. I know very little about
    javascript, a little more about PHP. Using yav (http://yav.sourceforge.net):

    <form method="POST" name=edit onsubmit="return performCheck('edit', rules,
    'classic');" action="pages_edit_submit.php">
    <input type="text" name="title">
    <input type="submit" name="Save">
    <input type="submit" name="Cancel">
    </form>

    .... PerformCheck fires when any submit button is click, which is logical but
    I'd like to prevent this if it was the cancel button that was clicked (and
    preserve form submission on pressing Enter whilst in the 'title' box.

    Very many thanks

    Nick
    Nick Bell, May 27, 2005
    #1
    1. Advertising

  2. Nick Bell

    Nick Bell Guest

    Self answering question.

    On 27/5/05 11:55 am, in article BEBCBB4B.256A%, "Nick Bell"
    <> wrote:

    > I'd like to prevent this if it was the cancel button that was clicked (and
    > preserve form submission on pressing Enter whilst in the 'title' box.


    Declare another variable e.g. Var canc=false
    In the onclick bit of the button you don't want to trigger the validation
    routine insert "canc=true;"
    In the onsubmit bit of <form> insert "return (performCheck() or canc);"

    Apologies for holding you up, hope the solution helps someone in the future

    Nick
    Nick Bell, May 27, 2005
    #2
    1. Advertising

  3. Nick Bell

    RobG Guest

    Nick Bell wrote:
    > I have a general form validation question. I know very little about
    > javascript, a little more about PHP. Using yav (http://yav.sourceforge.net):
    >
    > <form method="POST" name=edit onsubmit="return performCheck('edit', rules,
    > 'classic');" action="pages_edit_submit.php">
    > <input type="text" name="title">
    > <input type="submit" name="Save">
    > <input type="submit" name="Cancel">
    > </form>
    >
    > .... PerformCheck fires when any submit button is click, which is logical but
    > I'd like to prevent this if it was the cancel button that was clicked (and
    > preserve form submission on pressing Enter whilst in the 'title' box.
    >


    If you don't want the 'cancel' button to submit, don't make it a
    submit button. Presumably you want to run the validation but not
    submit the form, so why not just use a plain button with a
    appropriate label?

    <input type="button" value="Check form" onclick="
    performCheck('edit', rules,'classic');
    ">

    --
    Rob
    RobG, May 28, 2005
    #3
    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. Steve Franks
    Replies:
    1
    Views:
    422
    Juan T. Llibre
    Nov 1, 2005
  2. Replies:
    0
    Views:
    637
  3. Replies:
    2
    Views:
    507
    bruce barker
    Mar 25, 2008
  4. bnp
    Replies:
    4
    Views:
    298
  5. SAN CAZIANO
    Replies:
    8
    Views:
    166
    Dr John Stockton
    Oct 15, 2004
Loading...

Share This Page