I have a problem, I want to create two independent autocomplete one for a patient input and another for officials. The first works without problems, but when copying the second, changing the values are not autocomplete.
Any help is appreciated. Greetings!
Script in the index
//Este funciona $(function() { $( "#rut" ).autocomplete({ source: "conexion.php", minLength: 1, select: function( event, ui ) { $( "#nombre" ).val( ui.item.nombre_persona ); $( "#apellido" ).val( ui.item.apellido_persona ); } }) }); //este No funciona $(function() { $( "#run_f" ).autocomplete({ source: "conexion.php", minLength: 2, select: function( event, ui ) { $( "#nombre_f" ).val( ui.item.nombre_funcionario ); $( "#apellido_f" ).val( ui.item.apellido_funcionario ); } }) });
Query
if(isset($_GET['term'])){
$string = $_GET['term'];
}else{
$string = "";
}
$result = mysqli_query ($conexion, "SELECT * FROM paciente where run like '%$string%'");
if ($result){
$array = [];
$array_respuesta=[];
while ($row = mysqli_fetch_assoc($result)){
//print_r($row);
$array['label'] =$row ['run'];
$array['nombre_persona'] =$row ['nombre'];
$array['apellido_persona'] =$row ['apellido'];
array_push($array_respuesta, $array);
}
echo json_encode($array_respuesta);
}
if(isset($_GET['term']))
{
$string2 = $_GET['term'];
}else{
$string2 = "";
}
$result2 = mysqli_query ($conexion, "SELECT * FROM funcionario where run_funcionario like '%$string2%'");
if ($result2){
$array2 = [];
$array_respuesta2=[];
while ($row2 = mysqli_fetch_assoc($result2)){
//print_r($row);
$array2['run_f'] =$row2 ['run_funcionario'];
$array2['nombre_funcionario'] =$row2 ['nombre'];
$array2['apellido_funcionario'] =$row2 ['apellido'];
array_push($array_respuesta2, $array2);
}
echo json_encode($array_respuesta2);
}
patient input
<label for="rut">Run: </label>
<input type="text" name="rut" id="rut">
<br>
<label for="nombre">Nombre: </label>
<input type="text" name="nombre" id="nombre">
<br>
<label for="apellido">Apellido: </label>
<input type="text" name="apellido" id="apellido">
The official input
<label for="run_f">Podologa: </label>
<input type="text" name="run_f" id="run_f">
<br>
<label for="nombre_f">Nombre: </label>
<input type="text" name="nombre_f" id="nombre_f">
<br>
<label for="apellido_f">Apellido: </label>
<input type="text" name="apellido_f" id="apellido_f">