I need to select the document number of an Input from a list that is displayed, load the name to which that document number belongs in another Input. Example, when selecting the document number 12345, load me in another input, for example Pepito.
====ajax.php===
<?php
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = 'root';
$dbName = 'db_personas';
$db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
$searchTerm = $_GET['term'];
$query = $db->query("SELECT * FROM persona WHERE documento LIKE '%".$searchTerm."%' ORDER BY documento ASC");
while ($row = $query->fetch_assoc()) {
$data[] = $row['documento'];
}
echo json_encode($data);
?>
====index.php====
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<div style="width:520px;margin:0px auto;margin-top:30px;height:500px;">
<div class="col-md-6">
<div class="form-group">
<input id="documento" class="form-control" type="text" placeholder="Ingrese Número de Documento">
</div>
</div>
<br>
<div class="col-md-6">
<div class="form-group">
<input id="nombres" class="form-control" type="text">
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
$( "#documento").autocomplete({
source: 'ajax.php'
});
});
</script>
</body>
</html>