I have use auto complete with json and php. it works, but now I need to get the second array from the json.
This my script on source.php
<?php
$req = "SELECT namaBarang, harga FROM masternamabarang WHERE namaBarang LIKE '%".$_REQUEST['term']."%' ";
$query = mysql_query($req);
while($row = mysql_fetch_array($query))
{
$results[] = array('label' => $row['namaBarang'],'harga' => $row['harga']);
}
echo json_encode($results);
?>
and this script for autocomplate.php
<html>
<head>
<script src="js/jquery-1.9.1.js"></script>
<script src="json/js/jquery-ui-1.10.3.js"></script>
<script>
$(function()
{
$( "#NAMA" ).autocomplete({
source: 'source.php'
});
});
</script>
<script>
function ambil()
{
var x = document.getElementById('NAMA').value;
document.getElementById('HARGA').value=x;
}
</script>
</head>
<body>
<form>
<input type="text" name="NAMA" size="50" id="NAMA" onchange="ambil()"/><br>
<input type="text" name="HARGA" size="50" id="HARGA" />
</form>
</body>
The Autocomplete works well, but ALL I need is, take the second array[HARGA] from JSON array and fill it on text box HARGA.
I appreciate your answers.