Ver Mensaje Individual
  #7 (permalink)  
Antiguo 20/09/2007, 17:32
nicalvano
 
Fecha de Ingreso: agosto-2007
Mensajes: 3
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: llenado automatico de formulario

Cita:
Iniciado por wolfmao Ver Mensaje
y esperando !!
Yo resolví un problema similar con AJAX.

Crea un archivo .js donde guardes las siguientes funciones:

function nuevoAjax(){
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 cargadatos(ID)
{ var valor=id; AQUÍ RECIBES EL ID DEL REGISTRO QUE HAS CARGADO EN EL FORMULARIO
if(valor!='')
{ var eajax=nuevoAjax();
eajax.open("POST", "select_datos.php", true);
eajax.onreadystatechange=function()
{ if (eajax.readyState==4)
{ // Use the XML DOM to unpack the city and state data
var xmlDocument = eajax.responseXML;
document.getElementById('direccion').value = xmlDocument.getElementsByTagName('dir').item(0).fi rstChild.data;
document.getElementById('telefono').value = xmlDocument.getElementsByTagName('tel').item(0).fi rstChild.data;
}
}
eajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
// AQUÍ DEVUELVO LOS VALORES QUE CAPTURE
eajax.send("valor="+valor);
}
}


Debes crear un archivo select_datos.php para te va a procesar la informacion y a enviarla a la funcion anterior:

<?php

$coneccion=mysql_connect("host", "user", "password") or die(mysql_error());
mysql_select_db("db", $coneccion) or die(mysql_error());

$valor=$_POST["valor"];
if ($valor)
{conectar();
$seleccionM="select * from ListaEntidades where EntiId=$valor";
// Genero la consulta trayendo los datos de la entidad seleccionadas
$consultaM=mysql_query($seleccionM) or die ("No se ha realizado la consulta \n número de error" . mysql_errno() . "error " . mysql_error());
$registroD2=mysql_fetch_array($consultaM);
$direccion = $registroD2["Direccion"];
$telefono = $registroD2["Telefono"];

$return_value="<zip><dir>$direccion</dir><tel>$telefono</tel></zip>";

header('Content-Type: text/xml; charset=UTF-16');
echo $return_value; // This will become the response value for the XMLHttpRequest object
}
?>

luego desde tu onchange="cargadatos(registro['ID'])"

espero te funcione