2 submit button calling one page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian

    #1

    2 submit button calling one page

    I need to have 2 submit buttons in one form calling the same page. I just
    need to know which was used. Being able to pass a hidden form input for
    each would be ideal. How can I do this??

    Thanks!,Adrian


  • David Dorward

    #2
    Re: 2 submit button calling one page

    Adrian wrote:
    [color=blue]
    > I need to have 2 submit buttons in one form calling the same page. I just
    > need to know which was used.[/color]

    <input type="submit" name="s" value="1">
    <input type="submit" name="s" value="1">

    <?php

    print $_REQUEST['s'];

    ?>

    No need for JavaScript.


    --
    David Dorward <http://dorward.me.uk/>

    Comment

    • Michael Winter

      #3
      Re: 2 submit button calling one page

      On Tue, 20 Jan 2004 22:56:04 +0000, David Dorward <dorward@yahoo. com>
      wrote:
      [color=blue]
      > Adrian wrote:
      >[color=green]
      >> I need to have 2 submit buttons in one form calling the same page. I
      >> just
      >> need to know which was used.[/color]
      >
      > <input type="submit" name="s" value="1">
      > <input type="submit" name="s" value="1">
      >
      > <?php
      >
      > print $_REQUEST['s'];
      >
      > ?>
      >
      > No need for JavaScript.[/color]

      I assume that the values for the two buttons were supposed to be different?

      To the OP: If the submit button[1] has a name and value, that pair will be
      sent with the rest of the data on submission. If there is more than one
      button, only the clicked button will have its name/value pair sent. This
      will allow you to check which button was pressed server-side.

      If you need to check before the form is sent, I think the only way is to
      place onclick intrinsic events on the button elements. However, cancelling
      the click event might not (I can't remember) stop the form submission, if
      that was your intention.

      Mike


      [1] Either <input ... type="submit"> or <button ...
      type="submit">. ..</button>

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • Adrian

        #4
        Re: 2 submit button calling one page

        That worked great, thanks. I should have mentioned but I need to do it with
        type="image" and it does not work the same. Any work arounds?

        <input type="image" SRC="/image/shipcomplete.gi f" border="0" alt="Shipment
        Complete" name="action" value="Shipment Complete">
        <input type="image" SRC="/image/addnextcarton.g if" border="0" alt="Add Next
        Carton" name="action" value="AddNextC arton">

        result is:
        ACTION.Y=9
        ACTION.X=67

        when either buton is used.

        Thanks,Adrian



        "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
        news:opr13j2jtq 5vklcq@news-text.blueyonder .co.uk...[color=blue]
        > On Tue, 20 Jan 2004 22:56:04 +0000, David Dorward <dorward@yahoo. com>
        > wrote:
        >[color=green]
        > > Adrian wrote:
        > >[color=darkred]
        > >> I need to have 2 submit buttons in one form calling the same page. I
        > >> just
        > >> need to know which was used.[/color]
        > >
        > > <input type="submit" name="s" value="1">
        > > <input type="submit" name="s" value="1">
        > >
        > > <?php
        > >
        > > print $_REQUEST['s'];
        > >
        > > ?>
        > >
        > > No need for JavaScript.[/color]
        >
        > I assume that the values for the two buttons were supposed to be[/color]
        different?[color=blue]
        >
        > To the OP: If the submit button[1] has a name and value, that pair will be
        > sent with the rest of the data on submission. If there is more than one
        > button, only the clicked button will have its name/value pair sent. This
        > will allow you to check which button was pressed server-side.
        >
        > If you need to check before the form is sent, I think the only way is to
        > place onclick intrinsic events on the button elements. However, cancelling
        > the click event might not (I can't remember) stop the form submission, if
        > that was your intention.
        >
        > Mike
        >
        >
        > [1] Either <input ... type="submit"> or <button ...
        > type="submit">. ..</button>
        >
        > --
        > Michael Winter
        > M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]


        Comment

        • Michael Winter

          #5
          Re: 2 submit button calling one page

          On Tue, 20 Jan 2004 16:43:50 -0800, Adrian <adrian@nocrapp lease.ascc.com>
          wrote:
          [color=blue]
          > That worked great, thanks. I should have mentioned but I need to do it
          > with type="image" and it does not work the same. Any work arounds?[/color]

          You could do one of two things.

          1) Name the buttons differently. You could then check for the presence of
          either name, rather than one name and two different values[1].
          2) Use the BUTTON element, and place an IMG element inside it. This will
          keep the standard functionality, but it is rendered horribly by Internet
          Explorer. By contrast, it looks quite nice in Opera, and the button can be
          styled so that you can't even see it (IE ignores the same styling). I
          don't know how it will look in Mozilla and Netscape, but probably a lot
          better than IE.

          Mike

          [1] As you've probably found, you'll get name/value pairs of the form
          "name.x=nn" and "name.y=nn" where "nn" is the co-ordinates of the click,
          and "name" is the name of the control.

          --
          Michael Winter
          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

          Comment

          • Richard Cornford

            #6
            Re: 2 submit button calling one page

            "Adrian" <adrian@nocrapp lease.ascc.com> wrote in message
            news:buki9g$l09 $1@news.tdl.com ...[color=blue]
            >That worked great, thanks. I should have mentioned but I
            >need to do it with type="image" and it does not work the
            >same. Any work arounds?
            >
            > <input type="image" SRC="/image/shipcomplete.gi f"
            > border="0" alt="Shipment Complete" name="action"
            > value="Shipment Complete">
            > <input type="image" SRC="/image/addnextcarton.g if"
            > border="0" alt="Add Next Carton" name="action"
            > value="AddNextC arton">
            >
            > result is:
            > ACTION.Y=9
            > ACTION.X=67[/color]

            With <input type="image"> you get two name/value pairs instead of one
            and the value isn't necessarily useful. If the two INPUT fields had
            different names you would only get the name/value pairs from the button
            click on so the presence of (either on of) those name/value pairs,
            combined with the absence of either of the others would still tell you
            which INPUT was used.

            Also, you have named your INPUT elements "action" and that is a bad
            habit as forms already have an action property and that property will be
            overwritten by any form controls with a corresponding name. Rendering
            that form property unscriptable (at minimum). It is best no to use
            names/ids for form controls that correspond with any of the form's
            property names, but as JavaScript is case sensitive that is not
            difficult to achieve, initial capitals will do.

            Richard.


            Comment

            • Brynn

              #7
              Re: 2 submit button calling one page


              If you really want to use javascript for this ...

              <script language="javas cript">
              function whichButton(but tonNumber) {
              document.forms['myForm']['myButton'].value = buttonNumber;
              }
              </script>

              <input type="submit" onClick="whichB utton('1');>
              <input type="submit" onClick="whichB utton('2');>


              I think this should work fine ... but I would use non javascript
              examples first ... always ... html/ server-side obviously more
              reliable.

              Brynn


              On Tue, 20 Jan 2004 13:55:20 -0800, "Adrian"
              <adrian@nocrapp lease.ascc.com> wrote:
              [color=blue]
              >I need to have 2 submit buttons in one form calling the same page. I just
              >need to know which was used. Being able to pass a hidden form input for
              >each would be ideal. How can I do this??
              >
              >Thanks!,Adri an
              >
              >[/color]

              Brynn


              I participate in the group to help give examples of code.
              I do not guarantee the effects of any code posted.
              Test all code before use!

              Comment

              Working...