processing checkboxes
Hello
I am fairly new to JSPs. I basically have a simple page in which i will have bunch of checkboxes. user can select some checkboxes and click delete. once delete button is called i am going to a back end java code. How, in my java code, can I get which checkboxes were selected? can I get all the checkboxes that were selected as an array or list or any type of collection?
thanks!
# 1
>can I get all the checkboxes that were selected as an array or list or any type of collection?
Yes you can.
Give all the checkboxes the same name, with their value being the "id" of the thing you want to delete.
<input type="checkbox" name="deleteUser" value="42">
<input type="checkbox" name="deleteUser" value="69">
<input type="checkbox" name="deleteUser" value="666">
At the server end after you submit this form:
String[] idsToDelete = request.getParameterValues("deleteUser");
This String[] will have only the values of the checkboxes you have selected. It it then relatively simple to iterate through the array and call delete for each one.
Cheers,
evnafets