<?php
//Koneksi Ke Server Database
include_once "../librari/koneksi.php";
include_once "../librari/koneksi-auto.php";
include_once "../librari/librari.php";
?>
<html>
<head>
<link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/ui/ui.core.js"></script>
<script type="text/javascript" src="js/ui/ui.datepicker.js"></script>
<script type="text/javascript" src="js/ui/i18n/ui.datepicker-id.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#tanggal").datepicker({
dateFormat : 'yy-mm-dd',
changeMonth : true,
changeYear : true
});
});
</script>
<script language="javascript">
function kondisi(form)
{
if(form.txtNm.value=="")
{
alert("No Anggota Belum Di Pilih");
form.no_anggota.focus();
return(false);
}
if(form.tanggal.value=="")
{
alert("Tanggal Peminjaman Belum Di Isi");
form.tanggal.focus();
return(false);
}
if(form.TxtSimWaj.value=="")
{
alert("Simpanan Wajib Belum Di Isi");
form.TxtSimWaj.focus();
return(false);
}
return(true);
}
</script>
</head>
<body>
<form name="form1" method="post" action="SimpananTambahSim.php" onSubmit="return kondisi(this)" enctype="multipart/form-data">
<table width="500" border="0" cellspacing="2" cellpadding="0" class="keliling">
<tr bgcolor="#00CCFF">
<td colspan="2" bgcolor="#CCCCFF"><center><b> ENTRY DATA SIMPANAN</b></center></td>
</tr>
<tr>
<td width="300" align="right">Nomor Simpanan : </td>
<td width="300">
<input name="no_simpan" type="text" id="no_trans" value="<?php echo kdauto("simpanan","S"); ?>" disabled="disabled" />
<input name="no_simpan" type="hidden" id="no_trans" value="<?php echo kdauto("simpanan","S"); ?>" />
</tr>
<tr>
<td align="right">Nomor Anggota </td>
<td>
<?php
$result = mysql_query("select no_anggota, nm_anggota FROM anggota");
$jsArray = "var prdName = new Array();\n";
echo '<input name="no_anggota" onchange="changeValue(this.value)">';
while ($row = mysql_fetch_array($result)) {
$jsArray .= "prdName['" . $row['no_anggota'] . "'] = {nm_anggota:'" . addslashes($row['nm_anggota']) . "'};\n";
}
echo '</input>';
?>
<script type="text/javascript">
<?php echo $jsArray; ?>
function changeValue(id){
document.getElementById('prd_harga').value = prdName[id].nm_anggota;
};
</script>
<tr>
<td align="right">Nama Anggota : </td>
<td><input name="txtNm" type="text" id="prd_harga" readonly></td>
</tr>
<tr>
<td align="right">Tanggal Simpanan : </td>
<td><input id="tanggal" type="text" name="tanggal">
</tr>
<tr>
<td align="right">Simpanan Pokok : </td>
<td><input name="TxtSimpok" type="text"></td>
</tr>
</tr>
<td align="right">Simpanan Wajib : </td>
<td><input name="TxtSimWaj" type="text"></td>
</tr>
<tr>
<td> </td>
<td><input name="TbSimpan" type="submit" value="Tambah">
<input name="reset" type="reset" value="Cancel"></td>
</tr>
</table>
<br></br>
</div>
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db('nama_db');
$key = $_GET['term'];
$sql = "select * from anggota where no_anggota like '$key%'";
$json = array();
$query = mysql_query($sql);
while($data = mysql_fetch_array($query)){
//sesuaikan dengan struktur tabelmu
$json[] = array(
'label' => $data['no_anggota'],
'value' => $data['no_anggota'],
'nama' => $data['nama_anggota']
);
}
header("Content-Type: application/json");
echo json_encode($json);
?>
kedua update jquery dan jquery ui dengan yang terbaru, dan tambahkan auto complete<?php
//Koneksi Ke Server Database
include_once "../librari/koneksi.php";
include_once "../librari/koneksi-auto.php";
include_once "../librari/librari.php";
?>
<html>
<head>
<!-- update jquery dan jqueryui dengan yang terbaru -->
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/ui-lightness/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#tanggal").datepicker({
dateFormat : 'yy-mm-dd',
changeMonth : true,
changeYear : true
});
//tambahkan auto complete
$('#no_anggota').autocomplete({
source: "get_anggota.php",
minLength: 2,
select: function( event, ui ) {
$('#txtNm').val(ui.item.nama);
}
});
});
</script>
<script language="javascript">
function kondisi(form)
{
if(form.txtNm.value=="")
{
alert("No Anggota Belum Di Pilih");
form.no_anggota.focus();
return(false);
}
if(form.tanggal.value=="")
{
alert("Tanggal Peminjaman Belum Di Isi");
form.tanggal.focus();
return(false);
}
if(form.TxtSimWaj.value=="")
{
alert("Simpanan Wajib Belum Di Isi");
form.TxtSimWaj.focus();
return(false);
}
return(true);
}
</script>
</head>
<body>
<form name="form1" method="post" action="SimpananTambahSim.php" onSubmit="return kondisi(this)" enctype="multipart/form-data">
<table width="500" border="0" cellspacing="2" cellpadding="0" class="keliling">
<tr bgcolor="#00CCFF">
<td colspan="2" bgcolor="#CCCCFF"><center><b> ENTRY DATA SIMPANAN</b></center></td>
</tr>
<tr>
<td width="300" align="right">Nomor Simpanan : </td>
<td width="300">
<input name="no_simpan" type="text" id="no_trans" value="<?php echo kdauto("simpanan","S"); ?>" disabled="disabled" />
<input name="no_simpan" type="hidden" id="no_trans" value="<?php echo kdauto("simpanan","S"); ?>" />
</tr>
<tr>
<td align="right">Nomor Anggota </td>
<td>
<input name="no_anggota" type="text" id="no_anggota"/>
<tr>
<td align="right">Nama Anggota : </td>
<td><input name="txtNm" type="text" id="txtNm" readonly/></td>
</tr>
<tr>
<td align="right">Tanggal Simpanan : </td>
<td><input id="tanggal" type="text" name="tanggal">
</tr>
<tr>
<td align="right">Simpanan Pokok : </td>
<td><input name="TxtSimpok" type="text"></td>
</tr>
</tr>
<td align="right">Simpanan Wajib : </td>
<td><input name="TxtSimWaj" type="text"></td>
</tr>
<tr>
<td> </td>
<td><input name="TbSimpan" type="submit" value="Tambah">
<input name="reset" type="reset" value="Cancel"></td>
</tr>
</table>
<br></br>
</div>
</form>
</body>
</html>
//tambahkan auto complete
$('#no_anggota').autocomplete({
source: "get_anggota.php", // <--- digunakan disini
minLength: 2,
select: function( event, ui ) {
$('#txtNm').val(ui.item.nama);
}
});
file get_anggota.php untuk mencari nama anggota bukan untuk simpan, lebih jelasnya baca documentasi jqueryui autocomplete <?php
$con = mysql_connect("localhost","root","");
mysql_select_db('db_umroh');
$user=$_SESSION['login_user'];
$key=substr($user,-4);
$sql = "SELECT * FROM tabel_cabang WHERE id_cabang like '$key%'";
$json = array();
$query = mysql_query($sql);
while($data = mysql_fetch_array($query)){
//sesuaikan dengan struktur tabelmu
$json[] = array(
'label' => $data['id_cabang'],
'value' => $data['id_cabang'],
'nama' => $data['kota_cabang']
);
}
header("Content-Type: application/json");
echo json_encode($json);
?>
<script type="text/javascript">
//tambahkan auto complete
$('#id_cabang').autocomplete({
source: "get_data.php",
minLength: 40,
select: function( event, ui ) {
$('#txtNm').val(ui.item.nama);
}
});
});
</script>
<tr>
<td height="36">Cabang Kota</td>
<td><input name="txtNm" type="text" id="txtNm" /></td>
</tr>