Reputation: 5575
I'm developing a jsp/serlvet application. I have a page with a list of inputs as checkboxes . I want to send values of selected buttons to a servlet using ajax/jquery. In the servlet , I want to extract these values and use them .
for example:
I searched and found something like this :
$("#inboxDeleteSelected").click(function(){
var data = { 'checkBoxList[]' : []};
var list=$(":input:checkbox:checked"); // getting all selected checkboxes.
$(list.each(function() {
data['checkBoxList[]'].push($(this).val());
}));
$.post("servlet?do=deleteSelected",data,function(d){
// do something here
});
});
My questions:
Note:
I don't use submit button to submit the selected checkboxes,Indeed I use link/anchor to send those values .
Upvotes: 1
Views: 14413
Reputation: 597382
They are sent using their name, repeated:
servlet?do=deleteSelected&checkboxGroup=value1&checkboxGroup=value2
You can see that with the following simple html (after you press the submit button, take a look at the address bar):
<form method="get">
<input type="checkbox" name="checkboxGroup" value="1" />
<input type="checkbox" name="checkboxGroup" value="2" />
<input type="checkbox" name="checkboxGroup" value="3" />
<input type="submit" />
</form>
You obtain them using:
String[] values = request.getParameterValues("checkboxGroup");
Upvotes: 5