如何仅在php表中选择过滤数据中的所有复选框?我使用选项选择作为过滤器。 我尝试使用javascript,但它还会选择所有未过滤的数据。
这是我的代码
<?php
//cek session
if(empty($_SESSION['admin'])){
$_SESSION['err'] = '<center>Anda harus login terlebih dahulu!</center>';
header("Location: ./");
die();
} else {
include_once 'include/DB_Functions.php';
$db = new DB_Functions();
$akun=$_SESSION['nama_akun'];
$userid=$_SESSION['user_id'];
$i = 1;
$kontak = $db->daftarKontak($userid); ?>
<!-- Row Start -->
<div class="row">
<!-- Secondary Nav START -->
<div class="col s12">
<nav class="secondary-nav">
<div class="nav-wrapper blue-grey darken-1">
<ul class="left">
<li class="waves-effect waves-light"><a class="judul"><i class="material-icons">mail</i> Daftar Kontak</a></li>
</ul>
</div>
</nav>
</div>
<!-- Secondary Nav END -->
</div>
<div class="row">
<div class="input-field col s12">
<div class="col m12" id="colres">
<form id="kontak" class="col s12" method="POST" action="?page=tuj" enctype="multipart/form-data">
<br>
<select id="myInput" onChange="myFunction(event)" placeholder="Cari Grup" title="Type in a name">
<Option value="">Semua Kontak</option>
<option value="KADIV">KADIV</option>
<option value="KABAG">KABAG</option>
<option value="KASIE">KASIE</option>
<option value="BAG.">Bagian Bagian</option>
<option value="CABANG">Pimpinan Cabang</option>
<option value="AST">Asisten</option>
<option value="CAPEM">Pimpinan Capem</option>
<option value="KASPEM">Pimpinan Kaspem</option>
<option value="STAF">STAF</option>
<option value="CSO">CSO</option>
<option value="PINJ">Pinjaman</option>
<option value="ICU">ICU</option>
</select>
<b><label for="myInput">     Tampilkan Kontak Per Grup:</label></b>
<input type="text" id="Pilih" onSelect="nilai()" onkeypress="return cegah(event)" onkeyup="Function()" placeholder="Cari Berdasarkan Nama" title="Type in a name">
<?php echo str_repeat(' ', 261); ?><input type="checkbox" onclick="toggle(this, 'tujuan[]')" align="center" id="select_all"><label for="select_all"> PILIH SEMUA</label>
<center><table id="data-table" class="table table-striped table-bordered nowrap" width="100%">
<style>
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: white}
th {
background-color: grey ;
color: white;
}
</style>
<br><thead>
<tr>
<th width="15%">No.</th>
<th width="30%">Nama</th>
<th width="40%">Nama Akun</th>
<th width="15%">Pilih</th>
</tr>
</thead></br>
<tbody>
<?php
foreach($kontak as $value){
?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $value['NAMA'];?></td>
<td><?php echo $value['NAMA_AKUN'];?></td>
<td><input type="checkbox" class="cb" name="tujuan[]" id="<?php echo $i ?>" value="<?php echo $value['USER_ID'];?>"><label for="<?php echo $i ?>"></label></td>
<?php
$i++;
?>
</tr>
<?php
}
?>
</tbody>
</table></center>
<script>
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("data-table");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[2];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script language="JavaScript">
function toggle(source, id) {
checkboxes = document.getElementsByName(id);
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<script>
function pilsemh(master,group){
var cbArray = document.getElementsByClassName(group);
for(var i=0; i < cbArray.length; i++){
var cb = document.getElementById(cbArray[i].id);
cb.checked = master.checked;
}
}
</script>
<script>
function Function(e) {
var input, filter, table, tr, td, i;
input = document.getElementById("Pilih");
filter = input.value.toUpperCase();
table = document.getElementById("data-table");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
e = e || window.event;
var key = e.keyCode || e.charCode;
return key !== 13;
}
</script>
<script>
function cegah(e) {
document.getElementById("myInput").value="";
e = e || window.event;
var key = e.keyCode || e.charCode;
return key !== 13;
}
</script>
<button type="submit" name="kirim" class="btn-large blue waves-effect waves-light">Lanjut <i class="material-icons">done</i></button>
</form>
</div>
</div>
<!-- Row in form END -->
</div>
<!-- Form END -->
我认为代码可能包含几个错误,我正在尝试查找它们。我将不胜感激任何建议。 谢谢