Ver Mensaje Individual
  #6 (permalink)  
Antiguo 15/09/2011, 11:49
Avatar de Ximenitaa
Ximenitaa
 
Fecha de Ingreso: abril-2011
Ubicación: Mexico
Mensajes: 208
Antigüedad: 13 años
Puntos: 43
Respuesta: Autorellenado de inputs en formulario con Ajax/PHP/MySQL

este es el ultimo

Cita:
ajax2.php
Código PHP:
Ver original
  1. <?php
  2. include('conec.php');
  3. ?>
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>EMEH</title>
  10.  
  11. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  12. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
  13. <script >
  14.    
  15.     //funcion que limpia los demas campos
  16.     function LimpiarInput(destino,destino2)
  17.     {
  18.         destino.value="";  
  19.     }
  20.     //funcion que llena los datos
  21.     function LlenarDatos(text,destino,destino2)
  22.     {
  23.         //alert(''+text);
  24.         var datos = text.split('|'); //dividimos los datos para colocarlos en el lugar correcto    
  25.         destino.value = datos[0];
  26.         destino2.value = datos[1];
  27.     }
  28.    
  29.     //fucion con la cual obtenemos  los datos
  30.     function obten_datos(arrastre,destino,destino2,destino3,destino4,destino5)
  31.     {
  32.        
  33.         //alert("arrastre: "+arrastre+" destino: "+destino+" destino2: "+destino2+" destino3: "+destino3+" destino4: "+destino4+" destino5: "+destino5);
  34.         destino = document.getElementById(destino);
  35.         destino2 = document.getElementById(destino2);
  36.  
  37.         LimpiarInput(destino);
  38.         LimpiarInput(destino2);
  39.        
  40.         if(arrastre.options[arrastre.selectedIndex].value != 0)
  41.         {
  42.             arrastre.disabled = true;
  43.             destino.disabled = true;
  44.             destino.value = 'Cargando Nombre....';
  45.             destino2.disabled = true;
  46.             destino2.value = 'Cargando ApellidoP....';
  47.            
  48.             $.ajax({
  49.                 type: 'get',
  50.                 dataType: 'text',
  51.                 url: 'obtendatos.php',
  52.                 data: {valor: arrastre.options[arrastre.selectedIndex].value},
  53.                 success: function(text){
  54.                     LlenarDatos(text,destino,destino2,destino3,destino4,destino5);
  55.                     arrastre.disabled = false;
  56.                    
  57.                     destino.disabled = false;
  58.                     destino.readOnly = true;
  59.                    
  60.                     destino2.disabled = false;
  61.                     destino2.readOnly = true;
  62.                         }
  63.             });    
  64.         }
  65.     }
  66. </script>
  67. </head>
  68. <body>
  69.  
  70. <form id="form1" name="form1" method="post" action="">
  71.  
  72.   <table width="27%" border="0" cellspacing="0" cellpadding="0">
  73.     <tr>
  74.       <td width="38%">Trabajador &nbsp;&nbsp; </td>
  75.       <td width="62%"><label>
  76.         <select name="name" id="name" onchange="javascipt:obten_datos(this,'nombre','apaterno','amaterno','puesto','rfc');">
  77.           <option value="0">elige</option>
  78.           <?php
  79.             // creamos las opciones del select
  80.             $sql = new conectarMySQL("localhost","root","","prueba");
  81.             $sql->conectar();
  82.             $sql->consultar("SELECT id, nombre FROM trabajadores");
  83.             while ($row = $sql->obtendatos()){
  84.                 ?>
  85.                     <option value="<?php echo $row['id']; ?>"> <?php echo $row['nombre'];?></option>
  86.                    
  87.                 <?php
  88.             }
  89.             $sql->cerrarconexion();
  90.             $sql->limpiaconsulta();
  91.           ?>        
  92.         </select>
  93.       </label></td>
  94.     </tr>
  95.   </table> <br />
  96.    
  97. <table>
  98.     <tr>
  99.         <td>Nombre          </td>
  100.         <td>Apellido Paterno</td>
  101.         <td>Apellido Materno</td>
  102.        
  103.     </tr>
  104.  
  105.     <tr>   <td><label><input type="text" name="nombre"          id="nombre"    />       </label></td>
  106.            <td><label><input type="text" name="apaterno"        id="apaterno"  />       </label></td>
  107.            <td><label><input type="text" name="amaterno"        id="amaterno"  />       </label></td>
  108.      
  109.     </tr>          
  110. </table>
  111. </form>
  112.  
  113. <br />
  114. </body>
  115. </html>
__________________
❤(。◕‿◕)❤ . . . Ten un dia .... GeNiAl.... !!!! . . . ❤(◕‿◕。)❤

¿Que dia es hoy? . . . Hoy, hoy, es definitivamente un dia PERFECTO !!