Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/02/2011, 10:09
margarita02
 
Fecha de Ingreso: mayo-2007
Mensajes: 23
Antigüedad: 17 años
Puntos: 0
De acuerdo Respuesta: Combos dependientes by JQuery

Te dejo un codigo que me funciona perfecto:
dentro del header:
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script language="JavaScript" type="text/JavaScript">
$(document).ready(function(){
$("#depto").change(function(event){
var id = $("#depto").find(':selected').val();
$("#ciudad").load('genera-depto.php?id='+id);
});
});
</script>

en el body:
<tr><td class="celda" height="22" width="74">DEPTO: </td>
<td height="22" width="157"><?php
$res=@mysql_query("select * from depto");
printf ("<select name='depto' id='depto' style='font-family: Tahoma; font-size: 11px; width: 140px;' >");
echo "<option value=' ' selected>Selecciona un Depto</option>";
while($row1 = @mysql_fetch_array($res))
{
printf("<OPTION VALUE= %s> %s",$row1["id_depto"],htmlentities(strtoupper($row1["depto"])));
}
@mysql_free_result($res);
printf ("</select>");
?></td></tr>
<tr><td class="celda" width="74">CIUDAD :</td> <td width="157"><select name="ciudad" id="ciudad" style='font-family: Tahoma; font-size: 11px; width: 100px;'>
</select>
</td>

el codigo del archivo genera_depto.php

<?php
include ("../dbconnect.inc.php");

$consulta = "SELECT * from ciudad WHERE id_depto = ".$_GET['id'];
$query = @mysql_query($consulta);
while ($fila = @mysql_fetch_array($query)) {
echo '<option value="'.$fila['id_ciu'].'">'.htmlentities(strtoupper($fila['ciu'])).'</option>';
}@mysql_free_result($consulta);
?>

Espero te sirva