Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Dudas varias con Ajax

Estas en el tema de Dudas varias con Ajax en el foro de Frameworks JS en Foros del Web. Que tal amigos.... Estoy empezando a trabajar con Ajax y tengo una serie de dudas que no he sabido resolverlas: 1. En el siguiente script, ...
  #1 (permalink)  
Antiguo 08/05/2006, 07:34
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Pregunta Dudas varias con Ajax

Que tal amigos....

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-familyTrebuchet MSLucida Sans UnicodeArialsans-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> 
2. Como puedo lograr que recupere varios registros segun la consulta a la Base de Datos, es decir, en mi sql le pongo Limit 5 por ejemplo. Entonces mi pregunta es, Que debo modificar en el script anterior para que recupere los 5 registros que me retornara la consulta. He intentado colocar los input dentro de un ciclo for de php, pero no tengo ni idea de por que no me detecta este codigo, aparecen en la forma lo sigiente:

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>
Agradezco de antemano su valiosa colaboracion

Un Cordial Saludo
  #2 (permalink)  
Antiguo 09/05/2006, 11:57
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Que tal amigos.....

Tengo casi resueltas mis dudas.

[cita]
2. Como puedo lograr que recupere varios registros segun la consulta a la Base de Datos, es decir, en mi sql le pongo Limit 5 por ejemplo. Entonces mi pregunta es, Que debo modificar en el script anterior para que recupere los 5 registros que me retornara la consulta. He intentado colocar los input dentro de un ciclo for de php, pero no tengo ni idea de por que no me detecta este codigo, aparecen en la forma lo sigiente:

Nit :"; for ($j=0; $j<6; $j++) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>

[/cita]

el script lo tenia con extension .htm, entonces lo renombre con extension .php y listo

Eso fue todo... PERO ME TIRE COMO TRES DIAS PARA LLEGAR A ESTO haciendo pruebas y repruebas, cambiando esto por lo otro.... etc.

El script quedo asi:

Código PHP:
>
    /************************************************************************************************************
    (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;
    var currentNombreID=false;
        var ind = false;

    function getClientData(i)
    {
                var i = document.getElementById("ind").value;
        var clientId = document.getElementById("nit"+i).value.replace(/[^0-9]/g,'');
        var nombreId = false;
        if(clientId.length > 0 && clientId!=currentClientID) {
            currentClientID = clientId;
            ajax.requestFile = 'consul.php?accion=xnit&getClientId='+clientId;
        }

                ajax.onCompletion = function () {alert(ajax.response);}
                ajax.onCompletion = function () {showClientData();}
        ajax.runAJAX();
    }
    
    function getClientDataXNombre(i)
    {
                var i = document.getElementById("ind").value;
        var nombreId = document.getElementById("nombre"+i).value;
        var clienteId = false;
        
        if(nombreId.length > 0 && nombreId!=currentNombreID) {
            currentNombreID = nombreId;
            ajax.requestFile = 'consul.php?accion=xnombre&getNombreId='+nombreId;
        }
        
                //ajax.onCompletion = function () {alert(ajax.response);}
                ajax.onCompletion = function () {showClientData();}
        ajax.runAJAX();
    }

    function showClientData()
    {
        var formObj = document.forms['clientForm'];
        eval(ajax.response);
    }

    function initFormEvents()
    {
        var formObj = "";
                var i = document.getElementById("ind").value;
        document.getElementById('nit'+i).onblur = getClientData;
        document.getElementById('nombre'+i).onblur = getClientDataXNombre;
        document.getElementById('nit'+i).focus();
    }
    
    window.onload = initFormEvents;

    </script>
</head>

<body>
<table>
    <form name="clientForm" action="consul.php" method="post">
        <table align="center">
            <tr>
            <table>
            <td>Nit</td><td>Nombre</td><td>Direccion</td><td>Telefono</td><tr>
<?php
            
for ($i=0$i<10$i++) {
                echo 
"<td><input type='hidden' name='ind' id='ind' value='$i'>";
                echo 
"<input name='nit$i' id='nit$i'></td>";
                echo 
"<td><input name='nombre$i' id='nombre$i'></td>";
                echo 
"<td><input name='direccion$i' id='direccion$i'></td>";
                echo 
"<td><input name='telefono$i' id='telefono$i'></td><tr>";
            }
?>
            <tr>
            <td colspan="4" align="center"><input type="reset"></td></tr>
            </table>
        </table>    
    </form>
</table>
</body>
</html>
Como dicen por ahi... LA CONSTANCIA VENCE LO QUE LA DICHA.....

Pero me queda otro lio
Si quiero modificar digamos el contenido de la columna nombre del tercer registro.... ahi si perdi el año por que no detecta ningun cambio en dicha columna, ni en ninguna otra que este despues de la primera fila...

Si algun alma caritativa me puede ayudar.... lo agradeceria infinitamente

Un Cordial Saludo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:40.