Two submit buttons, can each call its own action?

Discussion in 'HTML' started by Fernie, Dec 5, 2004.

  1. Fernie

    Fernie Guest

    I have a form with a submit button that calls the following action:

    <form method="POST" action="Main.cgi?Catalog=PostEdit&CatName=Wheels">

    I decided to add a second button to delete the catalog but I am unsure how
    to proceed since both buttons call the script above. It would be great if
    the second script could call a second action but I do not know if this is
    possible.

    Here is my button code:

    <TD align="center"><FONT face="Arial" size="2"><INPUT type="submit"
    name="btnPost" value="Save changes"></FONT> <INPUT type="button"
    name="btnDeleteCatalog" value="Delete this catalog"></TD>

    Is it possible to have my second button submit its own script or am I taking
    the wrong approach?

    Thank you,

    Fernie



    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
    Fernie, Dec 5, 2004
    #1
    1. Advertising

  2. Fernie

    Fernie Guest

    Oh, by the way, the form has several fields on it and the data gets posted
    to the server.

    Thanks,

    Fernie



    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
    Fernie, Dec 5, 2004
    #2
    1. Advertising

  3. Fernie

    Fernie Guest

    I found a hodgepodge solution that works just fine but I don't like it
    because now I have to use javascript for the second button.

    The first button calls this:

    action="Main.cgi?Catalog=PostEdit&CatName=Wheels

    Using javascripts OnClick event, the second button can call this:

    action="Main.cgi?Catalog=Delete&CatName=Wheels



    In order to avoid relying on javascript for this, I am guessing that I can
    do something like this but I am not sure if this is is the right approach or
    even if it is possible:

    Create html something like this:

    action="Main.cgi?Catalog=Maintenance&CatName=Wheels

    My script on the server can then test if the button named btnPost was
    pressed or if the btnDeleteCatalog was pressed and take appropriate server
    side action. Is this the recommended way for doing this?

    Please advise,

    Fernie



    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
    Fernie, Dec 5, 2004
    #3
  4. Fernie

    Fernie Guest

    "Fernie" <Fernie@not_thisDocSignings.net> wrote in message
    news:FD57084EBEB6E240Fernie@not_thisDocSignings.net...
    > Create html something like this:
    >
    > action="Main.cgi?Catalog=Maintenance&CatName=Wheels
    >
    > My script on the server can then test if the button named btnPost was
    > pressed or if the btnDeleteCatalog was pressed and take appropriate server
    > side action. Is this the recommended way for doing this?


    Well, this method worked without having to use javascript but I do wish you
    could specify multiple actions and then call the one respective to your
    button but from what I understand, that is not possible.



    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
    Fernie, Dec 5, 2004
    #4
  5. Fernie

    RobM Guest

    "Fernie" <Fernie@not_thisDocSignings.net> wrote in message
    news:AC975624BDB6E240Fernie@not_thisDocSignings.net...
    > I have a form with a submit button that calls the following action:
    >
    > <form method="POST" action="Main.cgi?Catalog=PostEdit&CatName=Wheels">
    >
    > I decided to add a second button to delete the catalog but I am unsure how
    > to proceed since both buttons call the script above. It would be great if
    > the second script could call a second action but I do not know if this is
    > possible.
    >
    > Here is my button code:
    >
    > <TD align="center"><FONT face="Arial" size="2"><INPUT type="submit"
    > name="btnPost" value="Save changes"></FONT> <INPUT type="button"
    > name="btnDeleteCatalog" value="Delete this catalog"></TD>
    >
    > Is it possible to have my second button submit its own script or am I

    taking
    > the wrong approach?
    >
    > Thank you,
    >
    > Fernie


    Hi Fernie, I'm not sure on your server side language CGI, but I know the one
    I'm using (java) and also ASP you can get the value of the button same as
    getting the value of a field from the request (or whatever you call it in
    CGI). Have the two buttons named the same, but different values (e.g.
    'submit', 'delete') then get the value for the button (same name for both)
    and in your server script you can see which one was used and program
    accordingly.

    HTH
    Cheers
    Rob
    RobM, Dec 5, 2004
    #5
  6. Fernie wrote:

    > I have a form with a submit button that calls the following action:
    >
    > <form method="POST" action="Main.cgi?Catalog=PostEdit&CatName=Wheels">


    Invalid. & characters should be encoded as &amp; (unless you meet certain
    conditions which you don't).

    > I decided to add a second button to delete the catalog but I am unsure how
    > to proceed since both buttons call the script above.


    Give the two submit buttons a name and suitable value. Test for that in the
    server side script. Only the activated submit button is a successful
    control.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Dec 5, 2004
    #6
  7. Fernie

    Fernie Guest

    "David Dorward" <> wrote in message
    news:coulsu$f0m$1$...
    > Fernie wrote:
    >
    >> I have a form with a submit button that calls the following action:
    >>
    >> <form method="POST" action="Main.cgi?Catalog=PostEdit&CatName=Wheels">

    >
    > Invalid. & characters should be encoded as &amp; (unless you meet certain
    > conditions which you don't).
    >
    >> I decided to add a second button to delete the catalog but I am unsure
    >> how
    >> to proceed since both buttons call the script above.

    >
    > Give the two submit buttons a name and suitable value. Test for that in
    > the
    > server side script. Only the activated submit button is a successful
    > control.
    >
    > --
    > David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    > Home is where the ~/.bashrc is


    Hi David,

    Thank you for the correction, I was unaware that I was doing it incorrectly.
    The strange thing is that I'm able to retrieve the variable values on the
    server with no problem. I've only tested with IE6 and Firefox by the way.

    Regards,

    Fernie



    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
    Fernie, Dec 5, 2004
    #7
  8. Fernie

    Fernie Guest

    "RobM" <> wrote in message
    news:1NAsd.59756$...
    >
    > "Fernie" <Fernie@not_thisDocSignings.net> wrote in message
    > news:AC975624BDB6E240Fernie@not_thisDocSignings.net...
    >> I have a form with a submit button that calls the following action:
    >>
    >> <form method="POST" action="Main.cgi?Catalog=PostEdit&CatName=Wheels">
    >>
    >> I decided to add a second button to delete the catalog but I am unsure
    >> how
    >> to proceed since both buttons call the script above. It would be great
    >> if
    >> the second script could call a second action but I do not know if this is
    >> possible.
    >>
    >> Here is my button code:
    >>
    >> <TD align="center"><FONT face="Arial" size="2"><INPUT type="submit"
    >> name="btnPost" value="Save changes"></FONT> <INPUT type="button"
    >> name="btnDeleteCatalog" value="Delete this catalog"></TD>
    >>
    >> Is it possible to have my second button submit its own script or am I

    > taking
    >> the wrong approach?
    >>
    >> Thank you,
    >>
    >> Fernie

    >
    > Hi Fernie, I'm not sure on your server side language CGI, but I know the
    > one
    > I'm using (java) and also ASP you can get the value of the button same as
    > getting the value of a field from the request (or whatever you call it in
    > CGI). Have the two buttons named the same, but different values (e.g.
    > 'submit', 'delete') then get the value for the button (same name for both)
    > and in your server script you can see which one was used and program
    > accordingly.
    >
    > HTH
    > Cheers
    > Rob


    Rob, thank you for the explanation.

    Regards,

    Fernie




    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
    Fernie, Dec 5, 2004
    #8
  9. "Fernie" <Fernie@not_thisDocSignings.net> wrote:

    > I have a form with a submit button that calls the following action:
    >
    > <form method="POST" action="Main.cgi?Catalog=PostEdit&CatName=Wheels">


    Why? You will have some data passed the POST way, some passed the GET way.
    Why not simply do it the POST way using two additional hidden fields?

    > I decided to add a second button to delete the catalog but I am unsure
    > how to proceed since both buttons call the script above.


    Please try and describe the situation in more exact terms, and don't forget
    to include the URL next time. Buttons don't call anything.

    > It would be
    > great if the second script could call a second action


    What "second script"? It seems that you are mostly trying to make things
    more difficult by thinking in obscure terms. Nobody (including you) seems
    to know whether you are referring to client-side scripts or to server-side
    scripts.

    > <TD align="center"><FONT face="Arial" size="2"><INPUT type="submit"
    > name="btnPost" value="Save changes"></FONT> <INPUT type="button"
    > name="btnDeleteCatalog" value="Delete this catalog"></TD>


    Why reveal a fragment of code and not the real story?

    Setting font size smaller than the user's choice is either ignorance or
    insult. Stop that.

    And why would you use the unreliable type="button" for something that
    apparently _needs_ to work?

    > am I taking the wrong approach?


    Without knowing the real problem, I'm pretty sure the intended solution is
    wrong.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Dec 5, 2004
    #9
  10. Fernie wrote:

    >> Invalid. & characters should be encoded as &amp; (unless you meet certain
    >> conditions which you don't).


    > Thank you for the correction, I was unaware that I was doing it
    > incorrectly.


    I'm guessing that you are referring to the first paragraph of my comments.
    Please place your response directly under the relevant portion of quoted
    material and not quote material you are not discussing at all. It makes it
    a lot easier to follow the thread of a conversation.

    > The strange thing is that I'm able to retrieve the variable
    > values on the server with no problem. I've only tested with IE6 and
    > Firefox by the way.


    Many browsers perform error correction in order to cope with mistakes by
    authors, but not all browsers are created equal and will attempt to correct
    for various errors in different ways. Depending on this error correction is
    a bad idea.

    Tools such as <http://validator.w3.org/> will help you find syntax errors in
    your markup. Correcting them will increase the chances of HTML parsers
    being able to cope with your markup.

    > --


    A sig seperator is two dashes followed by a space. Please include the space
    to newsreaders can automatically trim off the sig.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Dec 5, 2004
    #10
    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. Saverio M.
    Replies:
    0
    Views:
    509
    Saverio M.
    Jul 3, 2006
  2. Derick van Niekerk
    Replies:
    8
    Views:
    468
    Carsten Haese
    Jan 27, 2006
  3. vyshu
    Replies:
    1
    Views:
    2,544
    Richard Senior
    Apr 27, 2007
  4. Marcelo

    Help - 3 action buttons on each record

    Marcelo, May 12, 2006, in forum: ASP General
    Replies:
    0
    Views:
    109
    Marcelo
    May 12, 2006
  5. Igor Nn
    Replies:
    7
    Views:
    435
    Johnny Morrice
    May 28, 2011
Loading...

Share This Page