Hola,
Una solución php-ajax:
index.php
Incluir en <head>:
<script type="text/javascript" src="func_ajax.js"></script>
Código PHP:
<?php
//Conexión
//Consulta
//..................................................................................................................
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">
<select id=\"cmbClientes\" onchange=\"peticAjax('sqldb.php',this.value)\">
<option value=''>--- Selecc. Cliente ---</option>";
while($cliente = mysql_fetch_array($tbl_clientes)){
echo "<option value=".$cliente['RFC'].">".$cliente['NOMBRE']."</option>";
}
echo "</select>
RFC:<input name=\"txtRFC\" type=\"text\" id=\"txtRFC\" size=\"3\" />
DIRECCIÓN:<input name=\"txtDIRECC\" type=\"text\" id=\"txtDIRECC\" size=\"60\" />
</form>";
//..................................................................................................................
?>
func_ajax.js Código PHP:
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();
}
//---
function peticAjax(pagina,cad){
var parametro = "RFC="+cad;
xmlhttp.open("POST",pagina,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
resp = xmlhttp.responseText;
registro = resp.split('::~::');
document.getElementById('txtRFC').value=registro[0];
document.getElementById('txtDIRECC').value=registro[1];
}
}
xmlhttp.send(parametro);
}
sqldb.php Código PHP:
<?php
$RFC=$_POST['RFC'];
//---
mysql_connect("servidor","usuario","clave");
mysql_select_db("basedatos");
$sql="select RFC,DIRECCION from clientes where RFC=$RFC";
$rs=mysql_query($sql);
$cliente = mysql_fetch_array($rs);
echo $cliente['RFC']."::~::".$cliente['DIRECCION'];
?>