hola a todos encontre un ejemplo como paises, ciudad y estados y lo probe y funciona, pero cuando lo adecuo a lo que necesito no me funciona; si me pueden ayudar a ver en que me equivoque porq he revisado y nada. primero colocare el original y luego el mio. gracias
Código PHP:
original formulario.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN†“http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script language="javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="javascript">
$(document).ready(function(){
$("#cmbpais").change(function () {
$("#cmbpais option:selected").each(function () {
elegido=$(this).val();
$.post("estados.php", { elegido: elegido }, function(data){
$("#cmbestados").html(data);
$("#cmbciudades").html("");
});
});
})
// Este puede ponerse en comentario si no se dispone de un 3er combo:
$("#cmbestados").change(function () {
$("#cmbestados option:selected").each(function () {
elegido=$(this).val();
$.post("ciudades.php", { elegido: elegido }, function(data){
$("#cmbciudades").html(data);
});
});
})
});
</script>
<body>
<form name="form1">
<center>
<table border = "1">
<tr><td>Pais:</td><td>
<select id="cmbpais">
<?php
include 'conexion.php';
conectar();
$consulta = "select * from paises";
$resultado = mysql_query($consulta);
if($fila=mysql_fetch_array($resultado)){
do{
echo '<option value="'.$fila['id_pais'].'">'.$fila['pais'].'</option>';
}while($fila = mysql_fetch_array($resultado));
}
desconectar();
?>
</select></td></tr>
<tr><td>Estado:</td><td><select id="cmbestados"></select></td></tr>
<tr><td>Ciudad:</td><td><select id="cmbciudades"></select></td></tr>
</table>
</center>
</form>
</body>
</html>
Código PHP:
estados.php
<?php
include 'conexion.php';
conectar();
$consulta = "select * from estados where id_pais = '$_POST[elegido]' order by estado";
$resultado = mysql_query($consulta);
$registros = mysql_fetch_row($resultado);
if($registros){
while($fila = mysql_fetch_array($resultado)){
echo "<option value=".$fila['id_estado'].">".$fila['estado']."</option>";
}
}
desconectar();
?>
Código PHP:
<?php
include 'conexion.php';
conectar();
$consulta = "select * from ciudades where id_estado = '$_POST[elegido]' order by ciudad";
$resultado = mysql_query($consulta);
$registros = mysql_fetch_row($resultado);
if($registros){
$resultado = mysql_query($consulta);
while($fila = mysql_fetch_array($resultado)){
echo "<option value=".$fila['id_ciudad'].">".$fila['ciudad']."</option>";
}
}
desconectar();
?>
en mi caso nada mas tengo dos combos lista.
Código PHP:
formulario.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN†“http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script language="javascript" src="jquery-1.3.2.min.js"></script>
<script language="javascript">
$(document).ready(function(){
$("#central").change(function () {
$("#central option:selected").each(function () {
elegido=$(this).val();
$.post("numeracion.php", { elegido: elegido }, function(data){
$("#cmbestados").html(data);
});
});
})
});
</script>
<body>
<form name="form1">
<center>
<table border = "1">
<tr><td>Central:</td><td>
<select id="central">
<?php
include ('conexion.php');
$conexion = obtenerConexion();
$consulta = "select * from tmatrizcpa1 order by id_matriz";
$resultado = mysql_query($consulta);
if($fila=mysql_fetch_array($resultado)){
do{
echo '<option value="'.$fila['id_matriz'].'">'.$fila['CENTRAL'].'</option>';
}while($fila = mysql_fetch_array($resultado));
}
?>
</select></td></tr>
<tr><td>Rangos:</td><td><select id="central"></select></td></tr>
</table>
</center>
</form>
</body>
Código PHP:
numeracion.php
<?php
include 'conexion.php';
$conexion = obtenerConexion();
$consulta = "select * from tnumeracion1 where id_matriz = '$_POST[elegido]'";
$resultado = mysql_query($consulta);
$registros = mysql_fetch_row($resultado);
if($registros){
while($fila = mysql_fetch_array($resultado)){
echo "<option value=".$fila['id_numeracion'].">".$fila['cRango']."</option>";
}
}
?>