Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/08/2013, 15:47
Sandiuga
 
Fecha de Ingreso: febrero-2013
Mensajes: 21
Antigüedad: 12 años, 1 mes
Puntos: 0
LLenar Formulario con input (AJAX)

Hola amigos a ver si me ayudan con este tema .

tengo un formulario , el cual lleno con un input evento (keyup)
y me carga la consulta por e valor que le ingreso en el input
hasta hay todo bien ,
lo que necesito hacer es que cuando tipee el input ,si no esta el registro en la consulta ,me debe traer/mostrar los inputs igual del formulario para yo llenarlos ,
pero como el ajax trae todo los input cargados de la consulta si el registro no existe
no se me muestran los input y no puedo llenarlos , se entiende?
en el fondo es si no esta el registro al tiepar el input me deben de aparecer igual los demas input para yo llenarlos y hacer el insert
he buscado info pero no encontrado y me he topado con varios ejemplos donde tienen el mismo problema
en la PAGINA2 tengo comentado un codigo al final que es el mismo formulario pero sin el resultado de la consulta , pero no se cmo mostrarlo
para poder llenarlo yo ..

a ver si me ayudan por favor !!
dejo el codigo para ser mas claro:
Saludos...

PAGINA 1:
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.  
  3.     function showUser(str)
  4.     {  
  5.        
  6.     if (str=="")
  7.  
  8.       {
  9.       document.getElementById("txtHint").innerHTML="";
  10.       return;
  11.       }
  12.     if (window.XMLHttpRequest)
  13.       {// code for IE7+, Firefox, Chrome, Opera, Safari
  14.       xmlhttp=new XMLHttpRequest();
  15.       }
  16.     else
  17.       {// code for IE6, IE5
  18.       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  19.       }
  20.     xmlhttp.onreadystatechange=function()
  21.       {
  22.       if (xmlhttp.readyState==4 && xmlhttp.status==200)
  23.         {
  24.         document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  25.         }
  26.       }
  27.     xmlhttp.open("GET","pagina2.php?q="+str,true);
  28.     xmlhttp.send();
  29.     }
  30. </script>

Código HTML:
Ver original
  1.  
  2. <div id="form">
  3.     <form id="form01" class="formular" method="post" action="usuarios_creados.php" name="form01" >
  4.     <b>Buscar / Crear nuevo Registro</b>
  5.     <br>
  6.     Rut :
  7.     <input value="" class="" type="text" name="numero"  id="numero" maxlength=12 onKeyUp="showUser(this.value)" />
  8.     <br>
  9.  
  10.        <div id="txtHint"></div>
  11.  
  12.         <input class="submit" type="submit" value="Guardar"/><hr/>
  13.     </form>
  14. </div>
  15. </body>
  16. </html>


PAGINA 2:
Código PHP:
<?php include("php_conexion.php"); 


$ms=$_GET["q"];

$sql="SELECT * FROM USUARIO WHERE ID = '".$ms."'";
$objParse oci_parse ($objConnect$sql);
oci_execute ($objParse);
while(
$row oci_fetch_array($objParse))
  {
  
echo 
'  <table border="0">';
echo 
'  <tr>';
echo 
'  <td valign="top">';
echo 
'  Nombre :';
echo 
'  <input value="'.$row['NOMBRES'].'" class="" type="text" name="nombres" id="nombres" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo 
'  <br>';
echo 
'  Apellidos :';
echo 
'  <input value="'.$row['APELLIDOS'].'" class="" type="text" name="apellidos" id="apellidos" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo 
'    <br>';
echo 
'  telefono :';
echo 
'  <input value="'.$row['TELEFONO'].'" class="" type="text" name="fono" id="fono" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo 
'    <br>';
echo 
' telefono fijo :';
echo 
'  <input value="'.$row['TELEFONO_FIJO'].'" class="" type="text" name="fono_2" id="fono_2" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo 
'    <br>';
echo 
'  mail:';
echo 
'  <input value="'.$row['MAIL'].'" class="" type="text" name="mail" id="mail" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
   
  }
oci_close($objConnect);


PODRIA MOSTRAR ESTE MISMO FORMULARIO PERO VACIOS  DEBERIA  SER  CON  IF MUESTRE FOMULARIO CON DATOS , ELSE FORMULARIO VACIO Y LLNERARLO  YO ,PERO COMO?


/*
echo '  <table border="0">';
echo '  <tr>';
echo '  <td valign="top">';
echo '  Nombre :';
echo '  <input value="" class="" type="text" name="nombres" id="nombres" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo '  <br>';
echo '  Apellidos :';
echo '  <input value="" class="" type="text" name="apellidos" id="apellidos" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo '    <br>';
echo '  telefono :';
echo '  <input value="" class="" type="text" name="fono" id="fono" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo '    <br>';
echo '  telefono fijo :';
echo '  <input value="" class="" type="text" name="fono_2" id="fono_2" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
echo '    <br>';
echo '  mail:';
echo '  <input value="" class="" type="text" name="mail" id="mail" maxlength="50" onKeyUp="this.value=this.value.toUpperCase();"/>';
*/



?>

Última edición por Sandiuga; 27/08/2013 a las 16:24