views:

50

answers:

3

Hi All,

I have form with two buttons having same name but different values ,how to get the value of both the buttons having same name but different value using request ?

<form action="controller">
    <input  class="smallbutton" name="op" value="login" type="submit"/>
    <input  class="smallbutton" name="op" value="SignUp" type="submit"/>
</form>

request.getParameter("op") gives only the value of login but not sign up.

A: 

I can't imagine why would you need such a thing. Two options, depending on what you are trying to acheive:

  • use request.getParameterValues("op")
  • use <input type="hidden" value=".." /> and change the value using javascript according to your usecase.

Please clarify what's the bottom-line, i.e. what are you trying to do.

Bozho
Generally, it is very useful if you can retrieve the value of the button to distinguish the button pressed when you have multiple buttons inside the same form.
BalusC
A: 

i think it depends whether you click on "SignUp" or on "login".

Since you cannot click on 2 buttons on 1 formular, you cannot get the 2 values

chburd
A: 

request.getParameter("op") gives only the value of login but not sign up.

This makes perfect sense. It returns the value of the pressed button. If you press Sign up then it will return signup. This way you know exactly what to do in the server side: login or signup. I really don't see any business reason why you would like to get the value for the both buttons regardless of the button pressed.

BalusC