B
benzema
Curioso
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Buenos días, tengo este autocompletar y no me funciona. Por favor podéis decirme donde está el fallo:
getClient.php
Gracias y un saludo
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento sin título</title>
<style type="text/css">
body{
background-repeat:no-repeat;
font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
height:100%;
background-color: #FFF;
margin:0px;
padding:0px;
background-image:url('/images/heading3.gif');
background-repeat:no-repeat;
padding-top:85px;
}
fieldset{
width:500px;
margin-left:10px;
}
</style>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">
var ajax = new sack();
var currenttelefono=false;
function getClientData()
{
var telefono = document.getElementById('telefono').value.replace(/[^0-9]/g,'');
if(telefono.length==9 && telefono!=currenttelefono){
currenttelefono = telefono
ajax.requestFile = 'getClient.php?gettelefono=' telefono; // Specifying which file to get
ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}
}
function showClientData()
{
var formObj = document.forms['clientForm'];
eval(ajax.response);
}
function initFormEvents()
{
document.getElementById('telefono').onblur = getClientData;
document.getElementById('telefono').focus();
}
window.onload = initFormEvents;
</script>
</head>
<body>
<form name="clientForm" action="ajax-client_lookup.html" method="post">
<fieldset>
<legend>Client information</legend>
<table>
<tr>
<td><label for="telefono">Nº Teléfono:</label></td>
<td><input name="telefono" id="telefono" size="9" maxlength="9"></td>
</tr>
<tr>
<td><label for="nombre">First name:</label></td>
<td><input name="nombre" id="nombre" size="20" maxlength="255"></td>
</tr>
<tr>
<td><label for="apellidos">Last name:</label></td>
<td><input name="apellidos" id="apellidos" size="20" maxlength="255"></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>
getClient.php
PHP:
<?php
/* Replace the data in these two lines with data for your db connection */
$connection = mysql_connect("localhost","root","root");
mysql_select_db("pruebas",$connection);
if(isset($_GET['gettelefono'])){
$res = mysql_query("select * from usuarios where telefono='".$_GET['gettelefono']."'") or die(mysql_error());
if($inf = mysql_fetch_array($res)){
echo "formObj.nombre.value = '".$inf["nombre"]."';\n";
echo "formObj.apellidos.value = '".$inf["apellidos"]."';\n";
}else{
echo "formObj.nombre.value = '';\n";
echo "formObj.apellidos.value = '';\n";
}
}
?>
Gracias y un saludo