How to make scripts for 2 submit buttons?

Discussion in 'Javascript' started by Penny, Jun 11, 2005.

  1. Penny

    Penny Guest

    Hi all,

    I have a checkout page in my online shopping cart that needs two submit
    buttons that direct to two seperate pages. Whichever button the user clicks,
    the destination page will use much the same values via Request.Form but will
    just do different things with them.

    One of the buttons will be a submit button. Can I have two submit buttons or
    even another button in the same form that redirects to a different page than
    the submit button redirects to but also allows the target page to use
    Request.Form to return the previous pages form values?

    Is there a javascript to do this?

    Sorry its so long winded.

    Regards

    Penny.
    Penny, Jun 11, 2005
    #1
    1. Advertising

  2. Penny

    Randy Webb Guest

    Penny wrote:
    > Hi all,
    >
    > I have a checkout page in my online shopping cart that needs two submit
    > buttons that direct to two seperate pages. Whichever button the user clicks,
    > the destination page will use much the same values via Request.Form but will
    > just do different things with them.
    >
    > One of the buttons will be a submit button. Can I have two submit buttons or
    > even another button in the same form that redirects to a different page than
    > the submit button redirects to but also allows the target page to use
    > Request.Form to return the previous pages form values?


    It is better to let the server determine what to do with the page, in
    case JS is disabled.

    > Is there a javascript to do this?


    <input type="submit" onclick="this.form.action='somePage.php'"
    value="somePage">

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, Jun 11, 2005
    #2
    1. Advertising

  3. Penny

    Penny Guest

    Hi Randy,

    > It is better to let the server determine what to do with the page, in
    > case JS is disabled.


    By this do you mean use ASP/PHP or the like to determine which page to
    redirect to?

    ><input type="submit" onclick="this.form.action='somePage.php'"

    value="somePage">

    Do you mean that you can have 2 submit buttons of the type "submit" and use
    each one's onclick to redirect accordingly?

    Regards

    Penny
    Penny, Jun 12, 2005
    #3
  4. Penny wrote:

    >> It is better to let the server determine what to do with the page, in
    >> case JS is disabled.


    > By this do you mean use ASP/PHP or the like to determine which page to
    > redirect to?


    Or whatever language you are using on the server.

    if ($_REQUEST['submit'] == "itemOne") {
    itemOne();
    } elsif ($_REQUEST['submit'] == "itemTwo") {
    itemTwo();
    } else {
    defaultBehaviour();
    }

    Just make sure you name your submit inputs. The activated one will be the
    only one which is successful.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Jun 12, 2005
    #4
  5. Penny

    Penny Guest

    Thanks David,

    Now I get it!

    Regards

    Penny
    Penny, Jun 13, 2005
    #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. Jan Danielsson
    Replies:
    8
    Views:
    608
    Mike Meyer
    Jul 22, 2005
  2. Jp Calderone
    Replies:
    0
    Views:
    443
    Jp Calderone
    Jul 21, 2005
  3. Replies:
    4
    Views:
    884
  4. davidj411
    Replies:
    0
    Views:
    480
    davidj411
    Jun 27, 2008
  5. Replies:
    13
    Views:
    513
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page