So, I am trying to create a tick box that has this action:
- The chkAll box , once been ticked, all other check boxes will also ticked.
- When this action happens, a button will appear.
Then, another action I am trying to achieve is, if two or more checkboxes (not included the chkAll box is ticked, the same button will appear too. This button is like a zip file button, so, only if more than one check box is ticked, it will appear (enabled to be used).
Currently the error I am facing is, 1.the chkAll check box needs to double click only then, the button appear.
2.And when I unclicked the chkAll check box, the button does disappear, but the other chckboxes are still ticked, which they suppose to be unticked too.
3.And when more than 1 check boxes are ticked, the button does not appear.
I am new to php, jquery, so will really appreciate any guidance from you. Thank you.
function toggleTick_Change() {
$('input[type=checkbox]').change(function() {
if ($("#chkAll").prop("checked")) {
$('input[type=checkbox]').prop('checked', $(this).prop("checked"));
$("#conditional-part").show();
} else if ($("#chkT").prop("checked")) {
if ($("#chkT").length > 1) {
$("#conditional-part").show();
} else {
$("#conditional-part").hide();
}
} else {
$("#conditional-part").hide();
}
});
}
#conditional-part {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<div class="content">
<div class="container">
<div id="page-container">
<div id="page-header">
<h3>Manage Deliveries</h3>
</div>
<div id="page-content">
<table align="center">
<tr id="conditional-part">
<td class="input-group " role="group" aria-label="..." style="width: 85px; margin-top: 2px;">
<input type="number" class="form-control input-xs" id="cpyCN{$rows.id}" name="cpyCN{$rows.id}" value="1" style="font-family: Raleway, Tahoma, Arial; font-size: 8pt; padding: 2px 2px 2px 10px;" placeholder="Copies" min="1" max="999" />
<span class="input-group-btn">
<button id="btnPrintCNTicked{$rows.id}" type="button" class="btn btn-primary btn-xs" style="width: 40px;"
onclick="javascript:btnPrintCNTicked_Click({$rows.id},$('#cpyCN{$rows.id}').val())">CN</button>
</span>
</td>
</tr>
</table>
<div class="table-responsive" style="margin-top: 10px;">
<table class="table table-hover table-bordered" style="font-size: 8pt;">
<thead>
<tr class="panel-default" style="height: 30px;">
<th style="width: 20px;">
<input type="checkbox" id="chkAll" style="width: 15px; height: 15px;" onchange="toggleTick_Change()" />
</th>
<th style="width: 40px;">
#
</th>
<th style="width: 140px;">
DELIVERY NO / <br>DATE / TYPE
</th>
</tr>
</thead>
<tbody>
<tr class="panel-default" style="height: 30px;">
<th style="width: 20px;">
<input type="checkbox" id="chkT" style="width: 15px; height: 15px;" onchange="toggleTick_Change()" />
</th>
<th style="width: 140px;">
abcd
</th>
</tr>
<tr class="panel-default" style="height: 30px;">
<th style="width: 20px;">
<input type="checkbox" id="chkT" style="width: 15px; height: 15px;" onchange="toggleTick_Change()" />
</th>
<th style="width: 140px;">
1234
</th>
</tr>
</tbody>
</table>
</div>
<!--/id -page content-->
</div>
<!--/id -page container-->
</div>
<!-- /container -->
</div>
<!-- /content -->