Two submit buttons, which one was pressed?

Discussion in 'Javascript' started by actionwoman63, Nov 23, 2004.

  1. Dear all

    I need to be able to check which one out of two submit buttons within
    the same form was pressed in a javascript function prior to form
    submission. And before I get flamed for not finding the answer in
    previous posts - I have already seen this question answered numerous
    times in this forum, only problem is that the recommended method is
    not available to me :-(. I know that if I could code an onclick event
    on the <input type=submit> tag, then call a function which sets a
    value corresponding to the button clicked, this would be a cinch, but
    I can't as I am working with a templated system which automatically
    generates the <input> tags.

    Question to you guys, is there any other way of getting this info in
    my javascript function?


    Code (shortened)
    ----------------

    <SCRIPT LANGUAGE="JavaScript1.1">

    function verify(f)
    {

    Need to put code in here to check which of the two submit buttons was
    pressed, as makes no sense to user to validate input when they press
    the 'cancel order' button.

    }
    </SCRIPT>

    <FORM onSubmit="return verify(this);" ACTION="somescript.exe"
    METHOD=POST>

    <INPUT TYPE=text NAME=delName VALUE="">
    <TEXTAREA ROWS=4 COLS=32 NAME=delAddr></TEXTAREA>
    <INPUT TYPE=text NAME=delTown VALUE="">

    <INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">
    <INPUT NAME="op-basket-confirm_order" TYPE=submit VALUE="Go To
    Checkout">

    </FORM>

    Grateful for any advice, or if anyone can spot a different workround
    to solve my problem.

    Actionwoman63
     
    actionwoman63, Nov 23, 2004
    #1
    1. Advertising

  2. In article <>,
    says...
    > Dear all
    >
    > I need to be able to check which one out of two submit buttons within
    > the same form was pressed in a javascript function prior to form
    > submission. And before I get flamed for not finding the answer in
    > previous posts - I have already seen this question answered numerous
    > times in this forum, only problem is that the recommended method is
    > not available to me :-(. I know that if I could code an onclick event
    > on the <input type=submit> tag, then call a function which sets a
    > value corresponding to the button clicked, this would be a cinch, but
    > I can't as I am working with a templated system which automatically
    > generates the <input> tags.
    >
    > Question to you guys, is there any other way of getting this info in
    > my javascript function?
    >
    >
    > Code (shortened)
    > ----------------
    >
    > <SCRIPT LANGUAGE="JavaScript1.1">
    >
    > function verify(f)
    > {
    >
    > Need to put code in here to check which of the two submit buttons was
    > pressed, as makes no sense to user to validate input when they press
    > the 'cancel order' button.
    >
    > }
    > </SCRIPT>
    >
    > <FORM onSubmit="return verify(this);" ACTION="somescript.exe"
    > METHOD=POST>
    >
    > <INPUT TYPE=text NAME=delName VALUE="">
    > <TEXTAREA ROWS=4 COLS=32 NAME=delAddr></TEXTAREA>
    > <INPUT TYPE=text NAME=delTown VALUE="">
    >
    > <INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">
    > <INPUT NAME="op-basket-confirm_order" TYPE=submit VALUE="Go To
    > Checkout">
    >
    > </FORM>
    >
    > Grateful for any advice, or if anyone can spot a different workround
    > to solve my problem.


    Write code that listens to a specific event for a particular object:

    <script for="op-basket-cancel_order" event="onclick"
    type="text/javascript">
    alert("You pressed op-basket-cancel_order");
    </script>

    <script for="op-basket-confirm_order" event="onclick"
    type="text/javascript">
    alert("You pressed op-basket-confirm_order");
    </script>

    <input type="button" name="op-basket-cancel_order" value="op-basket-
    cancel_order">
    <input type="button" name="op-basket-confirm_order" value="op-basket-
    confirm_order">

    --
    Hywel
     
    Hywel Jenkins, Nov 23, 2004
    #2
    1. Advertising

  3. On Tue, 23 Nov 2004 19:08:22 -0000, Hywel Jenkins
    <> wrote:

    [snip]

    > Write code that listens to a specific event for a particular object:
    >
    > <script for="op-basket-cancel_order" event="onclick"
    > type="text/javascript">
    > alert("You pressed op-basket-cancel_order");
    > </script>
    >
    > <script for="op-basket-confirm_order" event="onclick"
    > type="text/javascript">
    > alert("You pressed op-basket-confirm_order");
    > </script>


    Eww. Non-standard use of the SCRIPT element.

    You could use

    document.forms['formName/Id'].elements[
    'op-basket-cancel_order'
    ].onclick = function(evt) {
    /* Code here. */
    };

    document.forms['formName/Id'].elements[
    'op-basket-conform_order'
    ].onclick = function(evt) {
    /* Code here. */
    };

    added either onload (which could be added programatically, too), or in a
    SCRIPT element placed after the elements. After the FORM's closing tag
    might be safest.

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Nov 23, 2004
    #3
  4. actionwoman63

    Evertjan. Guest

    actionwoman63 wrote on 23 nov 2004 in comp.lang.javascript:

    > <FORM onSubmit="return verify(this);" ACTION="somescript.exe"
    > METHOD=POST>
    >
    > <INPUT TYPE=text NAME=delName VALUE="">
    > <TEXTAREA ROWS=4 COLS=32 NAME=delAddr></TEXTAREA>
    > <INPUT TYPE=text NAME=delTown VALUE="">
    >
    > <INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">
    > <INPUT NAME="op-basket-confirm_order" TYPE=submit VALUE="Go To
    > Checkout">
    >
    > </FORM>
    >


    If you are not in for the other poster's
    <script for="op-basket-cancel_order" coding,
    try this:

    =============================

    <form onsubmit="alert(clicked);return clicked=='confirm'"
    action="somescript.exe" method=post>

    <input type=text name=delname value="">
    <textarea rows=4 cols=32 name=deladdr></textarea>
    <input type=text name=deltown value="">

    <input name="op-basket-cancel_order" type=submit value="cancel order"
    onclick="clicked='cancel'">
    <input name="op-basket-confirm_order" type=submit
    value="go to checkout"
    onclick="clicked='confirm'">

    </form>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
     
    Evertjan., Nov 23, 2004
    #4
    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. D. Shane Fowlkes
    Replies:
    3
    Views:
    631
    S. Justin Gengo
    Feb 24, 2004
  2. Rune
    Replies:
    6
    Views:
    1,266
    Richie Hindle
    Jan 29, 2004
  3. Net Developer

    Three buttons - one is pressed down

    Net Developer, Jun 8, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    116
    Mythran
    Jun 8, 2005
  4. Mike P

    Two submit buttons within one <form>

    Mike P, Aug 14, 2008, in forum: ASP General
    Replies:
    2
    Views:
    156
    Evertjan.
    Aug 14, 2008
  5. Syed Ali

    Which Submit button was pressed?

    Syed Ali, Dec 16, 2003, in forum: Javascript
    Replies:
    8
    Views:
    93
    Thomas 'PointedEars' Lahn
    Dec 27, 2003
Loading...

Share This Page