Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Function tidak berjalan pada data yang kedua di tabel
Halo ! Saya newbie nih di web programming. Saya mau tanya mengenai modal menggunakan bootstrap. Saya memiliki dua data pada table. Saat akan melakukan update data pada modal, function berjalan dengan baik pada data pertama tapi pada data kedua function tidak jalan sama sekali. Mohon pencerahannya
<body>
<div class="adv-table">
<table class="table table-stripped table-hover datatab">
<thead>
<tr>
<th hidden>No</th>
<th hidden>ID Transaksi</th>
<th>Nama Nasabah</th>
<th>Alamat Pengiriman</th>
<th>Status</th>
<th>Detail</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, "SELECT * FROM status WHERE sender_username = '".$_SESSION['username']."' AND status_barang !='Diterima'");
$no = 1;
while ($data = mysqli_fetch_assoc($query))
{
?>
<tr>
<td hidden><?php echo $no++; ?></td>
<td hidden><?php echo $data['id']; ?></td>
<td><?php echo $data['nama_nsb']; ?></td>
<td><?php echo $data['alamat_pengiriman']; ?></td>
<td><?php echo $data['status_barang']; ?></td>
<td>
<!-- Button untuk modal -->
<a href="#myModal" type="button" class="btn btn-success btn-md" data-toggle="modal" onclick="func(); list();" data-target="#myModal<?php echo $data['id']; ?>">Update</a>
</td>
</tr>
<!-- Modal Edit Mahasiswa-->
<div class="modal fade" id="myModal<?php echo $data['id']; ?>" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Detail Status Pengiriman</h4>
</div>
<div class="modal-body">
<form role="form" action="upload_kurir.php" method="post">
<?php
$id = $data['id'];
$query_edit = mysqli_query($conn,"SELECT * FROM status WHERE id='$id'");
//$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_array($query_edit))
{
?>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<div class="form-group">
<label>No Rekening</label>
<input type="text" name="no_rek" class="form-control" readonly value="<?php echo $row['no_rek']; ?>">
</div>
<div class="form-group">
<label>Item</label>
<input type="text" name="item" class="form-control" readonly value="<?php echo $row['item']; ?>">
</div>
<div class="form-group">
<label>Nama Nasabah</label>
<input type="text" name="nama_nsb" class="form-control" readonly value="<?php echo $row['nama_nsb']; ?>">
</div>
<div class="form-group">
<label>Alamat Pengiriman</label>
<input type="text" name="alamat_pengiriman" class="form-control" readonly value="<?php echo $row['alamat_pengiriman']; ?>">
</div>
<div class="form-group">
<label>Status Terakhir</label>
<input type="text" id="status_terakhir" name="status_terakhir" class="form-control" readonly value="<?php echo $row['status_barang']; ?>">
</div>
<div class="form-group">
<label>Foto Penerima</label>
<input type="file" id="foto_penerima" name="foto_penerima" accept="image/*" capture>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Update</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
<?php
}
//mysql_close($host);
?>
</form>
</div>
</div>
</div>
</div>
<?php
}
?>
</tbody>
</table>
</div>
</body>
<script type="text/javascript">
function func()
{
var elem = document.getElementById("status_brg");
if(elem.value == "Pengiriman 1")
{
document.getElementById("alasan").readOnly = false;
document.getElementById("penerima").readOnly = true;
document.getElementById("location").value = "";
document.getElementById("foto_penerima").disabled = true;
document.getElementById("status_penerima").disabled = true;
document.getElementById("location").value = "";
}
if(elem.value == "Pengiriman 2")
{
document.getElementById("alasan").readOnly = false;
document.getElementById("penerima").readOnly = true;
document.getElementById("location").value = "";
document.getElementById("foto_penerima").disabled = true;
document.getElementById("status_penerima").disabled = true;
document.getElementById("location").value = "";
}
if(elem.value == "Retur")
{
document.getElementById("alasan").readOnly = false;
document.getElementById("penerima").readOnly = true;
document.getElementById("location").value = "";
document.getElementById("foto_penerima").disabled = true;
document.getElementById("status_penerima").disabled = true;
document.getElementById("location").value = "";
}
if(elem.value == "Diterima")
{
document.getElementById("alasan").readOnly = true;
document.getElementById("penerima").readOnly = false;
document.getElementById("foto_penerima").disabled = false;
document.getElementById("status_penerima").disabled = false;
document.getElementById("location").value = "-7.278280, 112.741846";
}
}
</script>
0
1 Jawaban:
coba di tambahin onclick="func();" juga di tombol update yang kedua, functionnya jelas gak jalan kalo gaada triggernya
<pre> <button type="submit" class="btn btn-success" onclick="func()">Update</button> </pre>
0