I'm trying to create a form that when we select the value on the autocomplete field it will fill another field, autocomplete is working fine but I can't make it fill the second field, can someone guide me a little bit?
Here is my .php
// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
if (isset($_GET['term'])) {
$query = "SELECT * FROM registo_obra WHERE Contrato LIKE '{$_GET['term']}%' LIMIT 25";
$result = mysqli_query($db, $query);
if (mysqli_num_rows($result) > 0) {
while ($user = mysqli_fetch_array($result)) {
$res['label'] = $user['Contrato'];
$res['cliente'] = $user['cliente'];
array_push( $return_arr, $res );
}
} else {
$res = array();
}
//return json res
echo json_encode($res),"\n";;
}
Here's my jQuery
<script>
$(function() {
$("#Editbox1").autocomplete({
source: "data2.php",
select: function (event, ui) {
var item = ui.item;
if(item) {
$("#wb_Text1").val(item.cliente);
}
}
});
});
</script>