|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
<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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > How to recognize two submit-typed buttons by name in a servlet? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|