I am facing an issue with retrieving the id of each table row when using the bootstrap checkbox-success. However, the normal checkbox allows me to successfully obtain the correct Id for each row. Can anyone assist me in troubleshooting my JavaScript code? Thank you in advance.
*Checkbox-success
<div class="checkbox checkbox-success pull-right" style="display:none !important;">
<input type="checkbox" name="incidentReportIds" id="incident_report_id" value="@item.incidentReportId" onchange="CheckCountOfSelectedIncident()" />
<label for="incident_report_id"></label>
</div>
*normal checkbox
<input type="checkbox" name="incidentReportIds" id="incident_report_id" value="@item.incidentReportId" onchange="CheckCountOfSelectedIncident()" style="display:none !important;"/>
*JavaScript function to check the value of each row
var $checkBoxesIncident = $('#tblAllIncidents').find('input[type="checkbox"]');
function CheckCountOfSelectedIncident() {
var $countChecked = $checkBoxesIncident.filter(':checked').length;
var check_count = $countChecked;
alert(check_count);
//works with normal checkbox
var checkedIRIds = [];
$.each($("input[name='incidentReportIds']:checked"), function () {
checkedIRIds.push($(this).val());
alert(checkedIRIds);
});
}
I am also having issues with CSS as the checkboxes in each row are not centered and aligned properly. In the image linked here, you can see that the checkboxes are misaligned. I have tried adjusting it via CSS but haven't succeeded. Here's a snippet of the HTML:
<div class="checkbox checkbox-success" style="display:none !important;">
<input type="checkbox" name="incidentReportIds" id="incident_report_id" value="@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7bea3b2baf9beb9b4beb3b2b9a385b2a7b8a5a39eb3fc97bea3b2baf9a4a3b6a3a2a499b6bab2">[email protected]</a>" onchange="CheckCountOfSelectedIncident()" />
<label for="incident_report_id"></label>
</div>
Full CSS for the checkboxes:
.checkbox {
padding-left: 20px;
}
.checkbox label {
display: inline-block;
vertical-align: middle;
position: relative;
padding-left: 5px;
}
...