I have a page that will have 4 separate datatables on the page. Each table will have a select/deselect all button. I am trying to get this working with only two tables so far. When I click the buttons it changes the button value from Select All to Deselect All and so on, but when I am on the first groups table and click the button nothing happens for the groups. The schedule records all get selected. Any ideas what I am doing wrong?
<script>
var checkflag = "false";
function checkGroups() {
var inputs = document.getElementsByClassName( 'group' );
if (checkflag == "false")
{
for (var i = 0; i < inputs.length; i++) {
inputs.checked = true;
}
checkflag = "true";
return "Deselect All";
}
else {
for (var i = 0; i < inputs.length; i++)
{
inputs.checked = false; }
checkflag = "false";
return "Select All";
}
}
var checkflag2 = "false";
function checkGroups() {
var inputs2 = document.getElementsByClassName( 'schedule' );
if (checkflag2 == "false")
{
for (var i = 0; i < inputs2.length; i++) {
inputs2.checked = true;
}
checkflag2 = "true";
return "Deselect All";
}
else {
for (var i = 0; i < inputs2.length; i++)
{
inputs2.checked = false; }
checkflag2 = "false";
return "Select All";
}
}
</script>
<div class="card-body">
<div class="card-datatable table-responsive">
<table id="request-list" class="table table-striped " style="border-style: none; ">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<cfloop query="grouplist">
<tr>
<td>
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input group" value="#id#" name="group" id="group">
<span class="custom-control-label">#displayname#</span>
</label>
</td>
</tr>
</cfloop>
</table>
</ul>
</div>
<div class="card-body">
<div class="card-datatable table-responsive">
<table id="schedule-list" class="table table-striped " style="border-style: none; ">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<cfloop query="schedulelist">
<tr>
<td>
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input schedule" value="#id#" name="schedule" id="schedule">
<span class="custom-control-label">#displayname#</span>
</label>
</td>
</tr>
</cfloop>
</table>
</ul>
</div>
<script>
$(document).ready(function() {
$('#request-list').DataTable( {
"dom": '<"toolbar">frtip',
"iDisplayLength": 500
} );
$("div.toolbar").html('<input class="btn btn-primary btn-sm md-btn-flat ml-3 checkall" type="button" name="CheckAll" id="checkall" value="Select All" onClick="this.value=checkGroups(this.form)" style="float:left;">');
} );
$(document).ready(function() {
$('#schedule-list').DataTable( {
"dom": '<"toolbar">frtip',
"iDisplayLength": 500
} );
$("div.toolbar").html('<input class="btn btn-primary btn-sm md-btn-flat ml-3 checkall2" type="button" name="CheckAll2" id="checkall2" value="Select All" onClick="this.value=checkScheds(this.form)" style="float:left;">');
} );
</script>