How Can I Select Multiple Checkboxes At Once?
I have a html table which is created dynamically. Im adding check box for each row. $.each(data, function(id, value) { rows.push('
Solution 1:
Change
$(document).on('change','.chkbox',function () {
var sites = [];
var value = $(this).val();
var res = value.split(":");
$.each($("input[class='chkbox']:checked"), function(){
sites.push(res[0]);
});
alert("sites are: " + sites.join(", "));
$.ajax({
type: "POST",
url: "http://localhost:8080/cache/setProcessing?site="+res[0]+"&client="+res[1],
/*data: {
chkbox: value
},*/
error : function(xhr, textStatus, errorThrown) {
alert("Failed. Error : " + errorThrown);
}
});
});
cor·re·spond·ing
$(document).on('change','.chkbox',function () {
var sites = [];
$.each($("input[class='chkbox']:checked"), function(){
var value = $(this).val(); // must me be inside the eachvar res = value.split(":"); // must me be inside the each
sites.push(res[0]);
});
alert("sites are: " + sites.join(", "));
$.ajax({
type: "POST",
url: "http://localhost:8080/cache/setProcessing?site="+res[0]+"&client="+res[1],
/*data: {
chkbox: value
},*/
error : function(xhr, textStatus, errorThrown) {
alert("Failed. Error : " + errorThrown);
}
});
});
Because in the previous code it only gets the value of the current checkbox you've clicked.
So you must put the value
and res
inside the each function
to know all checkboxes that have been checked and get there corresponding value..
Post a Comment for "How Can I Select Multiple Checkboxes At Once?"