Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/02/2008, 06:41
Carol_84
 
Fecha de Ingreso: septiembre-2007
Mensajes: 234
Antigüedad: 16 años, 8 meses
Puntos: 1
Exclamación Insetar en una BD y mostrar los datos introducidos en el formulario

Hola, haber si por favor, alguien puede ayudarme.
Yo en mi página tengo un formulario a través del cual se insertan los datos en la BD cuando se pulsa al boton de "modificar".( el archivo mostrardatospersonales.php hace la actualizacion en la BD)
Pues bien, lo que quiero es quitar el boton del formulario y hacer que cuando se inserten los datos en algún input del formulario, pues que se inserten directamnete en la BD y que además estos datos aparezcan tambien en la misma página sin necesidad de regargarla.
Lo que tengo hecho es:
Cita:
form id="formulario" name="form1" action ="mostrardatospersonales.php" method = "post">
<blockquote>
<tr>
<td class="label">Nombre</td>
<td><input type= "text" name ="nombre"onchange="pedirDatos()"></td>
</tr>
</br></br>
<tr>
<td class="label">Primer Apellido</td>
<td><input type= "text" name ="apellido1" onchange="pedirDatos()"></></td>
</tr>
</br></br>
<tr>
<td class="label">Segundo Apellido</td>
<td><input type= "text" name ="apellido2" onchange="pedirDatos()"></></td>
</tr>
</br></br>
<input type="submit" name = "modificar" value="Modificar">
<input type="button" value="Cancelar" onclick ="history.go(-1)"/>
</blockquote>
</form>


Luego en la capa en la que se muestra los resultados:
Cita:

<blockquote>
<div id="resultado">
<blockquote>Sus datos almacenados son: </blockquote>
<p><strong>Nombre </strong></p>
<p><strong>Primer Apellido </strong></p>
<p><strong>Segundo Apellido </strong></p>
<p><strong>Email </strong></p>
<p><strong>Doctor </strong></p>
<p><strong>Tel&eacute;fono</strong></p>
<p><strong>Perfil </strong></p>
</div>

el fichero .js que utilizo es:
Cita:
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function pedirDatos(){
//donde se mostrará el resultado
divResultado = document.getElementById('resultado');
//instanciamos el objetoAjax
ajax=objetoAjax();
//Se utiliza el medoto POST
ajax.open("POST", "ad_lista_usuarios2.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//se muestran los resultados en esta capa
divResultado.innerHTML = ajax.responseText
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.send(null)
}
El problema que tengo es que la función "pedirDatos()", la quiero aplicar para todos los campos del formulario y esta función devuelve null "ajax.send(null)"
Alguien sabe como puede arreglarlo??
Muchas gracias por adelantado!!