Two submit buttons, can each call its own action?

F

Fernie

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
 
F

Fernie

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

Thanks,

Fernie
 
F

Fernie

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
 
F

Fernie

Fernie said:
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.
 
R

RobM

Fernie said:
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
 
D

David Dorward

Fernie said:
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.
 
F

Fernie

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


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.

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
 
F

Fernie

RobM said:
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
 
J

Jukka K. Korpela

Fernie said:
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.
 
D

David Dorward

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top