I have an autocomplete form where I put the code and I automatically fill the other inputs with the information of the database but, I am not filling the other fields when I enter the code, I do not know what is wrong, they could help me.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<header>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<h1>Parsear o leer JSON con jquery</h1>
</header>
<section>
<form>
<fieldset>
<br><label for="codigo">Codigo</label>
<input type="text" name="codigo2" value="" class="text ui-widget-content ui-corner-all"><span id="resultado"></span><br>
<br><label for="nombre">Nombre</label>
<input type="text" name="nombre2" id="nombre2" value="" class="text ui-widget-content ui-corner-all"><br>
<br><label for="direccion">Direccion</label>
<input type="text" name="direccion2" id="direccion2" value="" class="text ui-widget-content ui-corner-all"><br>
<br><label for="telefono">Telefono</label>
<input type="text" name="telefono2" id="telefono2" value="" class="text ui-widget-content ui-corner-all"><br>
<br><label for="fechanac">fecha nacimiento</label>
<input type="text" name="fechanac2" id="fechanac2" value="" class="text ui-widget-content ui-corner-all"><br>
<br><label for="codpro">codigo de producto</label>
<input type="text" name="codpro2" id="codpro2" value="" class="text ui-widget-content ui-corner-all">
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#codigo2").focus();
$("#codigo2".keyUp(function(e){
;
var url="enter.php";
$.getJSON(url,(_num1 : $("#codigo2").val() ), function(clientes){
$.each(clientes, function(i,cliente){
$("#nombre2").val(cliente.nombre);
$("#direccion2").val(cliente.direccion);
$("#telefono2").val(cliente.telefono);
$("#fechanac2").val(cliente.fechanac);
$("#codpro2").val(cliente.codpro);
if (cliente.resultado =="0"){
$("#resultado").css("color","red");
$("#resultado").text("codigo no disponible");
}else{
$("#resultado").css("color","green");
$("#resultado").text("codigo no disponible");
}
});
});
});
});
</script>
</section>
</body>
</html>
enter.php
<?php
$cod = $_GET['_num1'];
if(!empty($cod){
comprobar($cod);
}
function comprobar($cod){
$con = mysqli_connect("localhost","root", "","bdventas");
mysqli_select_db('bdventas',$con);
$sql = mysqli_query("SELECT * FROM articulos WHERE codart = '".$cod."'",$con);
$clientes = array();
$contar = mysqli_num_rows($sql);
if($contar ==0) {
$clientes[] = array('codigo'=>'y', 'nombre'=>'y', 'direccion'=> 'y', 'telefono'=>'y', 'fechanac'=> 'y', 'codpro'=>'y',
'resultado'=> 2);
}else{
while ($row = mysqli_fecth_row($sql)){
$codigo=$row[0];
$nombre=$row[1];
$direccion=$row[2];
$telefono=$row[3];
$fechanac=$row[4];
$codpro=$row[5];
$clientes[] = array('codigo'=>$codigo, 'nombre'=>$nombre, 'direccion'=>$direccion, 'telefono'=>$telefono, 'fechanac'=>$fechanac,'codpro'=> $codpro,
'resultado'=> 1);
}
$json_string = json_encode($clientes);
echo $json_string;
}
?>