On a page, I have several checkboxes, the id is different for each. The number of checkbox is not fixed, may be one, 4, 10, … I’d like get all the id and send them via a $.post.
How can I do this ?
Thanks,
Update 1:
var jqxhr = $.post("/Controller/MyAction", {
field1: $("#field1").val(),
benefic: $(":checkbox").serialize(),
fileld2: $("#fileld2").val()
},
function (data) {
})
.success(function () {
})
.error(function (jqXHR, status, error) {
})
.complete(function () {
});
I don’t see any value in my controller for “benefic” … and it’s the “id” of selected checkbox I need
Do this:
If your checkboxes have the same name, for example
name="myCheckbox[]", you could do this:Hope this helps.
EDIT: Solution for your Update 1:
This will do what you ask for.. but, are you sure it will always be only 1 checkbox. selected? If you need more than 1 (i’m almost sure you do), in which format do you need to send them? Ids separated by commas?
To send all checked ids, separated by commas, you would do this:
Cheers