I have some checkboxes that work fine, but when I try to program their value in the following listener I can only check/uncheck the boxes via clicking on the table row, and not the checkbox:
$('body').on('click', '#sourceTable tbody tr', function() {
var r = dTable.fnGetData(this);
var boxId = r[2].substr(r[2].indexOf("id")+4, 7);
if (document.getElementById(boxId).checked){ //checked is true
document.getElementById(boxId).checked=false; //uncheck the box
}
else{
document.getElementById(boxId).checked=true; //check the box
}
});
Any idea how I can do both?
EDIT: With changes advised in answer below looks like this, only checkboxes are clickable not rows, data isn't being read from DataTable row either:
$('#sourceTable tbody tr, #sourceTable tbody tr td input').click(function (e) {
e.stopPropagation();
var r = dTable.fnGetData('#sourceTable tbody tr');
var boxId = r[2].substr(r[2].indexOf("id")+4, 7);
//alert($(boxId).val());
if (document.getElementById(boxId).checked){
document.getElementById(boxId).checked=false;
var i = PEMSToDisplay.indexOf(r[0]);
if(i != -1) {
PEMSToDisplay.splice(i, 1);
}
}
else{
document.getElementById(boxId).checked=true;
PEMSToDisplay.push(r[0]);
}
});