views:

49

answers:

2

There is one form, inside the form there are many checkboxes. Two operations can placed upon these ticked checkboxes. Since there is only one "submit" button for a form, how to walk around this?

I know I can set two buttons, one button for each operation, and an extra "submit" button, which looks like the pseudocode below:

<form>
<checkbox1>
<checkbox2>
<checkbox3>
...
<checkboxn>
<button value="operation1">
<button value="operation2">
<submit value="submit"></form>

but a user needs to click twice, is there a better solution? Maybe I can use JQuery to achieve it, how to write the code?

A: 

You dont need 3 buttons, you need one button or none. I dont know which language/framework you are using, but with one submit button in any of them is a matter of checking the checked or unchecked values of the checkboxes inside if/else/elseif/case sentences and executing the operations you want for each case. And you could also trigger a submit from a checkbox when is checked or unchecked, but that might be not pleasant for your users if you dont use ajax

Pablo
A: 

You can use bit of javascript to indicate which operation you want. Add a hidden field and 2 buttons for each operation. And when the button is clicked, set the value of the hidden field and submit the form. Your server side code can determine which operation to perform depending on the value of the hidden field.

Niran