Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/05/2006, 17:11
augusto_jaramil
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
HOLA AUGUSTO_JARAMIL,

Una vez analizado y haciendo pruebas.... como que le pegue al perro.

Te envio los scripts corregidos... (A mi me canciono como vos decis pero falto un detalle pendiente que al final te lo comento)

El codigo HTML quedaria asi;

Código PHP:
    var ajax = new sack();
    var 
currentClientID=false;

    function 
getClientData()
    {
        var 
clientId document.getElementById("nit").value.replace(/[^0-9]/g,'');
        if(
clientId.length && 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> 
Si notas la linea 10 la tengo en comentario (linea como viene el script original) porque me reporta un error onCompletion is not a function cosa rara que tiene el script ajax.js y que no supe que era.... Si alguien lo sabe le agradeceria me lo comentara (gracias)

La linea 11 tambien la tengo comentada. Si la dejo me muestra en una ventana la respuesta que da el servidor (a manera de alert)

Al fin la linea 12 es la que me da la respuesta para enviarla al form

Aqui si hay una cosa rara , la que te comentaba al inicio de la respuesta, en la linea 26, no se por que diantres no me detecta el onblur ..... tuve que oprimir la tecla F5 para que me detectara el cambio....

El script PHP quedaria asi:

Código PHP:
<?php
  ini_set
('session.cache_limiter''');
  
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
  
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  
header('Pragma: no-cache');
  
session_start(); 
/* Replace the data in these two lines with data for your db connection */
  
include ('lee_base.php');
  include (
'configuracion/abrirbd.php');

if(isset(
$_GET['getClientId'])){  
  
$nit $_GET['getClientId'];
  
$sql "Select nombre, direccion, telefono, ciudad, clase, estado from nits where nit=$nit";
  
$inf lee_todo($sql);

  if(
count($inf) > 0) {
    echo 
"formObj.nombre.value = '".$inf[0]["nombre"]."';\n";    
    echo 
"formObj.direccion.value = '".$inf[0]["direccion"]."';\n";    
    echo 
"formObj.telefono.value = '".$inf[0]["telefono"]."';\n";    
    echo 
"formObj.ciudad.value = '".$inf[0]["ciudad"]."';\n";    
    echo 
"formObj.clase.value = '".$inf[0]["clase"]."';\n";    
    echo 
"formObj.estado.value = '".$inf[0]["estado"]."'\n";    
    
  }else{
    echo 
"formObj.nombre.value = '';\n";    
    echo 
"formObj.direccion.value = '';\n";    
    echo 
"formObj.telefono.value = '';\n";    
    echo 
"formObj.ciudad.value = '';\n";    
    echo 
"formObj.clase.value = '';\n";    
    echo 
"formObj.estado.value = ''\n";      
  }    
}
?>
SI miras la lineas 22 y 30 le quite los ";" que hay antes del "\n" ya que, si los dejo, cuando el script html recibe el resultado se queda como esperando algun dato adicional

Espero te sirva

Un Cordial Saludo