I have a form. I want it to have two buttons (buttonA, buttonB). Is there a better way to figure out which button was clicked than keeping a hidden input field, and setting its value via javascript in onClick() to a different string for each?
This is what this article is demonstrating:
http://www.java2s.com/Code/Java/JSP/JspformUsingButtons.htm
But it seems a little weird, is there no better way than jumping through those hoops?
Thanks
You can use the
nameandvalueattributes to differentiate the buttons on the form, then read the appropriate value from the server. Here is an example:When
Button 1is clicked, the URL will containbutton=1, and of course whenButton 2is clicked,button=2.Obviously, you can use any
nameproperty you wish, as long as both buttons have the samename. This will work the same usingPOSTinstead ofGET.http://jsfiddle.net/M74xN/