I want make checkbox for checking all sub checkboxes.
My checkbox:
<table width="30%" class="table striped hovered cell-hovered border bordered">
<tr valign="middle">
<td><b>IDPEL</b></td>
<td><b>No. Baris</b></td>
<td><b><input type="checkbox" id="pilihsemua"/> Pilih Semua</b></td>
</tr>
<?php
foreach ($panel_error as $key) {
echo"<tr><td>".$key->errpanel."</td>";
echo"<td>".$key->nomorBaris."</td>";
echo"<td>";
echo form_checkbox('chk_boxes1[]',$key->errpanel);
echo"</td></tr>";
}
?>
</table>
and here is my script:
<script type="text/javascript">
$(document).ready(function () {
$('.chk_boxes').click(function(){
$('.chk_boxes1').attr('checked',checked)
})
$('#table1').dataTable();
$('#table2').dataTable();
//checkbox
$("#pilihsemua").click(function () { // If #pilihsemua checked, all checkbox will be checked.
$('.chk_boxes1[]').attr('checked', checked);
});
// if all sub checkboxes are being checked, #pilihsemua will automatically checked.
$(".chk_boxes1[]").click(function(){
if($(".chk_boxes1[]").length == $(".chk_boxes1[]:checked").length) {
$("#pilihsemua").attr("checked", "checked");
} else {
$("#pilihsemua").removeAttr("checked");
}
});
//end of checkbox
});
</script>
But still, I don't know why, it can't be work. I try to check #pilihsemua but all the sub classes doesn't be checked. Or if I checked all the sub classes, the #pilihsemuadoesn't be checked too.
Aucun commentaire:
Enregistrer un commentaire