Need Javascript Advice

Discussion in 'Javascript' started by amerar@iwc.net, Jan 18, 2006.

  1. Guest

    Hi All,

    Here is my situation: I have a form where the user can perform a
    number of tasks. One of these tasks is to enter a new record. The
    form has an 'onsubmit' property to validate the data if the users
    enters a new record.

    However, there is also a button to allow the user to 'duplicate' a
    stored record. In that case, I do not want to perform the entire
    validation since most of the data will be fetched from the database
    behind the scene. But, when the form submits, the 'onsubmit' property
    takes off and attempts to validate the form......

    What is the best way to handle this? Basically different behaviors
    when the form is submitted??

    I'm not a good Javascript programmer, so explaining throughly would
    really help.

    Thanks,

    Arthur
    , Jan 18, 2006
    #1
    1. Advertising

  2. wrote:

    > Here is my situation: I have a form where the user can perform a
    > number of tasks. One of these tasks is to enter a new record. The
    > form has an 'onsubmit' property to validate the data if the users
    > enters a new record.


    Actually, the `form' element has an intrinsic event handler attribute
    for handling its `submit' event, named `onsubmit'.

    > However, there is also a button to allow the user to 'duplicate' a
    > stored record. In that case, I do not want to perform the entire
    > validation since most of the data will be fetched from the database
    > behind the scene. But, when the form submits, the 'onsubmit'
    > property takes off and attempts to validate the form......
    >
    > What is the best way to handle this? Basically different behaviors
    > when the form is submitted??


    You need to find out which submit button was activated. The following
    example should be self-explaining:

    <script type="text/javascript">
    function validate(f)
    {
    if (f && arguments.callee.submit.name != "duplicate")
    {
    // perform validation, return `false' if the result is negative
    }

    return true;
    }
    validate.submit = {};
    </script>

    <form ... onsubmit="return validate(this);">
    ...
    <input type="submit" value="Submit"
    onclick="validate.submit = this;">
    <input type="submit" name="duplicate" value="Duplicate"
    onclick="validate.submit = this;">
    </form>


    HTH

    PointedEars
    Thomas 'PointedEars' Lahn, Jan 18, 2006
    #2
    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. Asun Friere
    Replies:
    1
    Views:
    484
    Paul Boddie
    Aug 27, 2003
  2. Peter Hansen
    Replies:
    23
    Views:
    841
    Anton Vredegoor
    Sep 5, 2003
  3. Gerrit Holl
    Replies:
    16
    Views:
    603
    Tom Plunket
    Aug 29, 2003
  4. Asun Friere
    Replies:
    0
    Views:
    468
    Asun Friere
    Aug 28, 2003
  5. Michele Simionato
    Replies:
    2
    Views:
    374
    Jacek Generowicz
    Sep 1, 2003
Loading...

Share This Page