Ver Mensaje Individual
  #2  
Antiguo 11-07-2007
jgutti jgutti is offline
Miembro
 
Registrado: may 2003
Posts: 189
Reputación: 22
jgutti Va por buen camino
Gabriel, esto lo puedes hacer con ajax+php, adjunto ejemplo:

# index.php
<?
$hostname_testing = "localhost";
$database_testing = "testing";
$username_testing = "testing";
$password_testing = "testing";
$testing = mysql_connect($hostname_testing, $username_testing, $password_testing) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_testing, $testing);
$query_combo1 = "SELECT * FROM municipios";
$combo1 = mysql_query($query_combo1, $testing) or die(mysql_error());
$row = mysql_fetch_assoc($combo1);
?>
<html>
<head>
<title>Combos</title>
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
</head>
<body>
<form name="f1" method="post">
<select name="municipios" onChange="optionMuni();">
<option value="0">[ Seleccione ]</option>
<? do { ?>
<option value="<? echo $row['id_muni']?>"><? echo $row['nom_muni']?></option>
<? } while ($row = mysql_fetch_assoc($combo1)); ?>
</select>
<div id="localidad"><select><option>[ Seleccione ]</option></select></div>
</form>
</body>
</html>
<? mysql_free_result($combo1); ?>


# ajax.js
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 optionMuni(){
divResultado = document.getElementById('localidad');
id_muni=document.f1.municipios.value;
ajax=objetoAjax();
ajax.open("POST", "localidad.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
divResultado.innerHTML = ajax.responseText
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("id_muni="+id_muni)
}


# localidad.php
<?
$hostname_testing = "localhost";
$database_testing = "testing";
$username_testing = "testing";
$password_testing = "testing";
$testing = mysql_connect($hostname_testing, $username_testing, $password_testing) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_testing, $testing);
mysql_select_db($database_testing, $testing);
$query_localidades = "SELECT localidades.id_local, localidades.nom_local FROM localidades WHERE localidades.id_muni=". $_POST['id_muni'];
$localidades = mysql_query($query_localidades, $testing) or die(mysql_error());
$row = mysql_fetch_assoc($localidades);
?>
<select name="localidades">
<option value="0">[ Seleccione ]</option>
<? do { ?>
<option value="<? echo $row['id_local']?>"><? echo $row['nom_local']?></option>
<? } while ($row = mysql_fetch_assoc($localidades));?>
</select>
<? mysql_free_result($localidades); ?>
Responder Con Cita