Postingan lainnya
update data tanpa reload page
assalamualaikum , saya ingin bertanya bagiamana cara update data tanpa reload halaman :soalnya pada saat saya masuk di form , ada pilihan untuk pilih department , setelah saya pilh muncul beberapa data usulan, nah ada data usulan ygn saya ingin edit , pas berhasil edit ,halamannya malah reload dan saya harus kembali pilih deprtmen...saya mnta bntuannya supaya setelah update data hlammnya tetap pada sesi selcted yang dipilih.
saya lampirkan gambar dan codingnya
<a href='https://imgur.com/MFrei8o'>https://imgur.com/MFrei8o</a> <a href='https://imgur.com/a/bHwPReY'>https://imgur.com/a/bHwPReY</a>
<?php
$dept=$_SESSION['namauser'];
?>
<script type="text/javascript">
$(function() {
$("#theTable.satu tr:even").addClass("stripe1");
$("#theTable.satu tr:odd").addClass("stripe2");
$("#theTable.satu tr").hover(
function() {
$(this).toggleClass("highlight");
},
function() {
$(this).toggleClass("highlight");
}
);
});
function deleteRow(ID) {
var id = ID;
var pilih = confirm('Cetak Usulan No. = '+id+ '?');
if (pilih==true) {
$.ajax({
type : "POST",
url : "modul/pinjaman/ctk.php",
data : "id="+id,
success : function(data){
$("#tampil_data1").load("modul/pinjaman/tampil_data1.php");
}
});
}
}
</script>
<script language="javascript" src="modul/pinjaman2/ajax.js"></script>
<style type="text/css">
button {
margin: 1px;
position: relative;
padding: 4px 8px 4px 4px;
cursor: pointer;
list-style: none;
}
.a {
margin: 1px;
position: relative;
padding: 4px 8px 4px 4px;
cursor: pointer;
list-style: none;
width:50px;
font-size:10px;
}
button span.ui-icon {
float: left;
margin: 0 4px;
}
</style>
<form method="POST" action="">
<select name="ftoko" class="d form-control">
<option value=all> ~ Semua Dept ~
<?php
//include '../../inc/inc.koneksi.php';
$qrystrk = "select DISTINCT(username) from os_dept a left join os_ga b on a.username=b.dept where a.username not in ('bmmks','bm') ";
$resultk = mysql_query($qrystrk);
$no=1;
while ($row = mysql_fetch_array($resultk, MYSQL_BOTH)) {
$no++;
echo "<option value=\"" . $row['username'] . "\">" .$row['username'];
}
mysql_free_result($resultk);
?>
</select>
<input type="submit" value="CARI" name="ok"/>
</form>
<?php
if(isset($_POST['ok'])){
$user=$_POST['ftoko'];
$filshop = "";
if ($_POST['ftoko']!="all") {
$filshop = " and dept='" .$_POST['ftoko']. "'";
}
// www.contoh-ta.com
//author : asep setiawan & Team
ini_set('display_errors', 1);
ini_set('error_reporting', E_ERROR);
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';
include '../../inc/fungsi_koperasi.php';
$tgl1 = $_POST['tgl1'];
$tgl2 = $_POST['tgl2'];
if(!empty($tgl1)) {
$where = " WHERE tgl BETWEEN '$tgl1' AND '$tgl2'";
}else{
$where ="";
}
echo "
<div id='tampil_data'>
<table id='theTable' class='satu' width='100%'>
<tr>
<th rowspan='2' width='5%'>No</th>
<th rowspan='2'>No usulan</th>
<th rowspan='2'>Tgl Usulan</th>
<th rowspan='2'>Dept Tujuan</th>
<th rowspan='2'>Deskripsi</th>
<th rowspan='2'>qty</th>
<th colspan='2'>BM</th>
<th rowspan='2'>STATUS</th>
</tr>
<tr>
<th colspan='2'>Approve</th>
</tr>
";
$sql = "select * from os_ga where usulan>'2018-09-01' and pesanan='0000-00-00' and pengerjaan='0000-00-00' " .$filshop. " order by usulan desc" ;
$query = mysql_query($sql);
$no=1;
while($rows=mysql_fetch_array($query)){
echo "<tr>
<td align='center'>$no</td>
<td align='center'>$rows[id]</td>
<td align='center'>$rows[usulan]</td>
<td align='center'>$rows[tujuan]</td>
<td align='center'>$rows[deskripsi]</td>
<td align='right'>".number_format($rows[qty])."</td>
";
if ($rows['keterangan']=='Y') {
echo"
<td align='center' bgcolor='#00FF00'>
<a href=\"../../osga/modul/pinjaman2/approve.php?id=" . $rows['id'] . "&kd=". $rows['kd'] ."\" target=\"_self\" onclick='return false;'>YA</a>
</td>
<td align='center' bgcolor='#00FF00'>
<a href=\"../../osga/modul/pinjaman2/rejected.php?id=" . $rows['id'] . "&kd=". $rows['kd'] ."\" target=\"_self\" onclick='return false;'>TDK</a>
</td>
";
}elseif($rows['keterangan']=='N'){
echo"
<td align='center' bgcolor='#ff7607'>
<a href=\"../../osga/modul/pinjaman2/approve.php?id=" . $rows['id'] . "&kd=". $rows['kd'] ."\" target=\"_self\" onclick='return false;'>YA</a>
</td>
<td align='center' bgcolor='#ff7607'>
<a href=\"../../osga/modul/pinjaman2/rejected.php?id=" . $rows['id'] . "&kd=". $rows['kd'] ."\" target=\"_self\" onclick='return false;'>TDK</a>
</td>
";
}else{
echo"
<td align='center' bgcolor='#FFFFFF'>
<a href=\"../../osga/modul/pinjaman2/approve.php?id=" . $rows['id'] . "&kd=". $rows['kd'] ."\" target=\"_self\">YA</a>
</td>
<td align='center' bgcolor='#FFFFFF'>
<a href=\"../../osga/modul/pinjaman2/rejected.php?id=" . $rows['id'] . "&kd=". $rows['kd'] ."\" target=\"_self\" >TDK</a>
</td>
";
}
if ($rows['keterangan']=='Y') {
echo "
<td align='center' bgcolor='#00FF00'>
<b>APPROVE</b>
</td>
";
}elseif($rows['keterangan']=='N'){
echo "
<td align='center' bgcolor='#ff7607'>
<b>REJECT</b>
</td>
";
}
/*
elseif($rows['keterangan']=='N'){
echo "
<td align='center' bgcolor='#ff7607'>
<b>REJECT</b>
</td>
";
}*/else{
echo "
<td align='center' bgcolor='#FFFFFF'>
<b>WAIT</b>
</td>
";
}
echo"</tr>";
$no++;
}
echo "
</table>
</div>
";
}
?>
7 Jawaban:
Mungkin pada saat formnya di submit formnya di prevent terlebih dahulu
coba post ftoko ditangkep, terus dicocokkan sama selectbox <pre> <select name="ftoko" class="d form-control"> <option value=all> ~ Semua Dept ~ <?php //include '../../inc/inc.koneksi.php';
$qrystrk = "select DISTINCT(username) from os_dept a left join os_ga b on a.username=b.dept where a.username not in ('bmmks','bm') ";
$resultk = mysql_query($qrystrk);
$no=1;
while ($row = mysql_fetch_array($resultk, MYSQL_BOTH)) {
$no++;
echo "&lt;option value=\"" . $row['username'] . "\" ".($_POST['ftoko'] == $row['username'] ? 'selected' : '')."&gt;" .$row['username'];
}
mysql_free_result($resultk);
?&gt;
&lt;/select&gt; </pre>
<pre>($_POST['ftoko'] == $row['username'] ? 'selected' : '')</pre>
klaw yng ini apa maksudnya gan ? saya kurang paham
jadi jika yang dipilih sama dengan yg ada diselectbox, makan otomatis ke select gan
apakah kalau pagenya ke reload ,
<pre>($_POST['ftoko'] == $row['username'] ? 'selected' : '')</pre>
selected di atas masih berfungsi ?