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?
But it seems a little weird, is there no better way than jumping through those hoops?
Thanks
解决方案
You can use the name and value attributes to differentiate the buttons on the form, then read the appropriate value from the server. Here is an example:
Button One
Button Two
When Button 1 is clicked, the URL will contain button=1, and of course when Button 2 is clicked, button=2.
Obviously, you can use any name property you wish, as long as both buttons have the same name. This will work the same using POST instead of GET.