Código PHP:
<script Language="JavaScript" Type="text/javascript">
function CargaMunicVive() {
var i=0;
var longitud;
var o = new Array;
var indice=0;
var valor;
valor=(document.egresados.cmb_codidere.options[document.egresados.cmb_codidere.selectedIndex].value);
<?php
$result = mysql_query("SELECT * FROM tb_departamentos ORDER BY id");
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result)){
$cddep=$row["id"];
$rest = mysql_query("SELECT * FROM tb_municipios WHERE relacion='$cddep' ORDER BY id");
$rows = mysql_fetch_array($rest);
echo " if (valor=='$cddep') {\n";
echo " var j=0;\n";
echo " o[i++]=new Option('Elija un Municipio');\n";
echo " document.egresados.cmb_codimure.options[j]=o[j];\n\n";
while($rows = mysql_fetch_array($rest)) {
$cdmun=$rows["id"];
$dsmun=$rows["opcion"];
echo " o[i++]=new Option('$dsmun');\n";
echo " j=j+1;\n";
echo " document.egresados.cmb_codimure.options[j]=o[j];\n\n";
}
echo "document.egresados.cmb_codimure.length=o.length;\n";
echo "}\n\n";
}
?>
}
</script>
Código PHP:
<select name="cmb_codidere" id="cmb_codidere" onchange='CargaMunicVive()'>
<option selected="selected">Seleccione el departamento</option>
<?php
$result=mysql_query("SELECT * FROM tb_departamentos ORDER BY id");
$row = mysql_fetch_array($result);
$i=1;
while($row = mysql_fetch_array($result)) {
$cddep=$row["id"];
$dsdep=$row["opcion"];
echo "<option value='$cddep'>$dsdep</option>";
$i++;
}
mysql_free_result($result);
?>
</select>
Código PHP:
<select name="cmb_codimure" id="cmb_codimure" onchange='CargaMunicNace()'>
<option selected="selected">Seleccione el Municipio</option>
</select>
Espero me entiendan y puedan ayudarme gracias.