Retroceder   Foros del Web > Programación para sitios web > AJAX

Respuesta
 
Herramientas Desplegado
Antiguo 08-may-2006, 07:34   #1 (permalink)
augusto_jaramil ha deshabilitado el karma
 
Fecha de Ingreso: junio-2004
Mensajes: 335
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
augusto_jaramil está desconectado   Responder Citando
Antiguo 09-may-2006, 11:57   #2 (permalink)
augusto_jaramil ha deshabilitado el karma
 
Fecha de Ingreso: junio-2004
Mensajes: 335
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
augusto_jaramil está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 15:09.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93