Estoy empezando a trabajar con Ajax y tengo una serie de dudas que no he sabido resolverlas:
1. En el siguiente script, No me canciona el onblur (linea 63), debo darle recargar a la pagina (tecla F5) para que me detecte el contenido del campo y ahi si arranca la ejecucion del script
Código PHP:
<html> <head>
<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="AJAX/ajax.js"></script>
<script type="text/javascript">
/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
Thank you!
www.dhtmlgoodies.com
Alf Magne Kalleland
************************************************************************************************************/
var ajax = new sack();
var currentClientID=false;
function getClientData()
{
var clientId = document.getElementById("nit").value.replace(/[^0-9]/g,'');
if(clientId.length > 0 && clientId!=currentClientID) {
currentClientID = clientId;
ajax.requestFile = 'consulta.php?getClientId='+clientId;
ajax.onCompletion = showClientData();
//ajax.onCompletion = function () {alert(ajax.response);}
ajax.onCompletion = function () {showClientData()}
ajax.runAJAX();
}
}
function showClientData()
{
var formObj = document.forms['clientForm'];
eval(ajax.response);
}
function initFormEvents()
{
document.getElementById('nit').onblur = getClientData();
document.getElementById('nit').focus();
}
window.onload = initFormEvents;
</script>
</head>
<body>
<form name="clientForm" action="consulta.php" method="post">
<legend>Informacion de Clientes</legend>
<table>
<tr>
<td>Nit :</td>
<td><input name="nit" id="nit" size="15" maxlength="14"></td>
</tr>
<tr>
<td>Nombre :</td>
<td><input name="nombre" id="nombre" size="15" maxlength="14"></td>
</tr>
<tr>
<td>Direccion :</td>
<td><input name="direccion" id="direccion" size="15" maxlength="14"></td>
</tr>
<tr>
<td>Telefono :</td>
<td><input name="telefono" id="telefono" size="15" maxlength="14"></td>
</tr>
<tr>
<td>Ciudad :</td>
<td><input name="ciudad" id="ciudad" size="15" maxlength="14"></td>
</tr>
<tr>
<td>Clase :</td>
<td><input name="clase" id="clase" size="15" maxlength="14"></td>
</tr>
<tr>
<td>Estado :</td>
<td><input name="estado" id="estado" size="15" maxlength="14"></td>
</tr>
</table>
</form>
</body>
</html>
Nit :"; for ($j=0; $j<6; $j++) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
El codigo modificado que tengo para esto es el siguiente:
Código PHP:
<body>
<form name="clientForm" action="consulta.php" method="post">
<legend>Informacion de Clientes</legend>
<table>
<tr>
<?php
echo "<td>Nit :</td><td>Nombre :</td><td>Direccion :</td><td>Telefono :</td><td>Ciudad :</td><td>Clase :</td><td>Estado :</td><tr>";
for ($j=0; $j<6; $j++) {
echo "<td><input name='nit$j' id='nit$j' size='15' maxlength='14'></td>";
echo "<td><input name='nombre$j' id='nombre$j' size='15' maxlength='14'></td>";
echo "<td><input name='direccion$j' id='direccion$j' size='15' maxlength='14'></td>";
echo "<td><input name='telefono$j' id='telefono$j' size='15' maxlength='14'></td>";
echo "<td><input name='ciudad$j' id='ciudad$j' size='15' maxlength='14'></td>";
echo "<td><input name='clase$j' id='clase$j' size='15' maxlength='14'></td>";
echo "<td><input name='estado$j' id='estado$j' size='15' maxlength='14'></td></tr>";
}
?>
</table>
</form>
</body>
Un Cordial Saludo