<form id="form1" name="form1" method="post" action="">
<table width="361" border="1" align="center">
<tr>
<td width="121">ID ANGGOTA </td>
<td width="224"><input name="id_angg" type="text" id="id_angg" /> </td>
</tr>
<tr>
<td>Nama</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Alamat</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Telp</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>ID BUKU </td>
<td><input name="id_buku" type="text" id="id_buku" /></td>
</tr>
<tr>
<td>Judul</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Penulis</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Penerbit</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Tgl Pinjam </td>
<td><input name="tgl_pinjam" type="text" id="tgl_pinjam" /></td>
</tr>
<tr>
<td>Tgl Kembali </td>
<td><input name="tgl_kembali" type="text" id="tgl_kembali" />
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" />
</td>
</tr>
</table>
</form>
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$sql = "select * from tb_anggota where id_anggota like '%".$_GET['term']."%'";
$result = mysql_query($sql);
$json = array();
while($data = mysql_fetch_assoc($result)){
$data['label'] = $data['id_anggota'].' - '.$data['nama_anggota'];
$data['value'] = $data['id_anggota'];
$json[] = $data;
}
header("Content-Type: application/json");
echo json_encode($json);
kemudian ubah form menjadi seperti:<html>
<head>
<!-- tambahkan jquery dan jqueryui-->
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="361" border="1" align="center">
<tr>
<td width="121">ID ANGGOTA </td>
<td width="224"><input name="id_angg" type="text" id="id_angg" /> </td>
</tr>
<tr>
<td>Nama</td>
<td><span id="nama"></span></td>
</tr>
<tr>
<td>Alamat</td>
<td><span id="alamat"></span></td>
</tr>
<tr>
<td>Telp</td>
<td><span id="telp"></span></td>
</tr>
<tr>
<td>ID BUKU </td>
<td><input name="id_buku" type="text" id="id_buku" /></td>
</tr>
<tr>
<td>Judul</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Penulis</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Penerbit</td>
<td><? echo "";?></td>
</tr>
<tr>
<td>Tgl Pinjam </td>
<td><input name="tgl_pinjam" type="text" id="tgl_pinjam" /></td>
</tr>
<tr>
<td>Tgl Kembali </td>
<td><input name="tgl_kembali" type="text" id="tgl_kembali" />
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" />
</td>
</tr>
</table>
<script type="text/javascript">
$(function() {
$( "#id_angg" ).autocomplete({
minLength: 0,
source: 'get-data.php',
select: function( event, ui ) {
$( "#id_angg" ).val( ui.item.value );
$( "#nama" ).html( ui.item.nama_anggota );
$( "#alamat" ).html( ui.item.alamat_anggota );
}
});
});
</script>
</form>
</body>
</html>
pada saat mengetik id anggota akan muncul sugesti dan saat dipillih data anggota akan muncul. Lakukan hal yang sama untuk buku.