The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
How to recognize two submit-typed buttons by name in a servlet?
Discuss How to recognize two submit-typed buttons by name in a servlet? in the Java Help forum on Dev Shed. How to recognize two submit-typed buttons by name in a servlet? Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 11th, 2000, 03:02 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 4

Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
<form
name=form1
action="userActionServlet"
method="post"
>
//...
<input
type=submit
name=calculate
value="Calculate"
>
<input
type=submit
name=save
value=" Save "
>
If I intend to use my ActionServlet to
perform both 'calculate' and 'save'
functionalities, I need to know
which 'submit' button is hit. So,
How do I know which one is hit via
the 'name' property--or some other
way?
Is this possible?
OR, is it possible to associate
two servlets to two submit-buttons
for a single form?
It seems CGI guys do use two named
submit buttons with a single form.
Am I right in this?
Thanks in advance.
------------------
Regards,
Tony
|

July 15th, 2000, 09:47 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: Guayquil, Ecuador
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hi, the best solution i can think of is manipulating the form in the client side, by doing this:
two javascript functions to be called in the onclick event for each submit button.
As you can imagine if you click the first button you will get some values for the form fields (using hidden fields could be good idea) and if you click the second one you get other values, doing this the servlet will "know" wich submit has been clicked.
I think you can also select the "action" for the form dinamically with javascript, allowing this to use to different servlets.
An example function to manipulate form values is:
<input type=submit name=calculate value=""
onclick=calculate()>
<input type=submit name=save value=""
onclick=save()>
....
function calculate(){
document.formname.calculate.value="calculate";
//document.formname.submit
}
function save(){
document.formname.save.value="save";
//document.formname.submit
}
this code is not tested, but is something like that
Bye
Hope it helps.
OttoX
|

July 17th, 2000, 12:45 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 4

Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hi Ottox,
Thanks a lot to you for your answer which
sparked me into yet another solution
to my origninal question:
if I put
<form
name=form1
action="userActionServlet"
method="POST"
>
//...
<input
type=submit
name=submit
value="Calculate">
<input
type=reset
name=reset
value=Reset">
<input
type=submit
name=submit
value="Save">
then I can use
out.prinlnt("<BR>"+req.getParameter("submit")+"<BR>"));
to get the 'value' of the clicked submit
button. In such way, I can know which
submit-typed button is clicked and fire a
corresponding action inside the
ActionServlet.
Thank you again, Ottox. Keep cool!
------------------
Regards,
Tony
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|