elementos del formulario los 3 combos que se relacionan
Código HTML:
Número de personas </td> <td> <? $bd_host = "10.33.143.3"; $bd_usuario = "tacopnet_root"; $bd_password = "y+y-u*u/"; $bd_base = "tacopnet_tacop"; $con = mysql_connect($bd_host, $bd_usuario, $bd_password); mysql_select_db($bd_base, $con); $sql = "SELECT * from cotizador"; $rs = mysql_query($sql, $con); ?> <select name="nump" id="nump" onChange="componer_Centros(this.value);presta()" style="margin-left:10px;"> <option value="">--Seleccione--</option> <? if(mysql_num_rows($rs)>0) { while($row = mysql_fetch_assoc($rs)) { ?> <option value="<?=$row["id"]?>"><?=$row["nump"]?></option> <? } } ?> </select> </td> </tr> <tr> <td> Modelo </td> <td> <select name="modelo" id="modelo" style="margin-left:10px;background:#FFFFFF;" > <option value=""></option> </select> </td> </tr> <tr> <td> Precio de contado </td> <td> $<select name="precioc" id="precioc" style="background:#FFFFFF;"> <option value=""></option> </select> </td> </tr>
Código Javascript:
Ver original
<script> function componer_Centros(cod_area) { document.miformulario.modelo.length=0; document.miformulario.precioc.length=0; document.miformulario.modelo.options[0] = new Option("","","defaultSelected",""); document.miformulario.precioc.options[0] = new Option("","","defaultSelected",""); var indice=1; <? $sql_depto = "SELECT * from cotizador"; $rs_depto = mysql_query($sql_depto, $con); if(mysql_num_rows($rs_depto)>0) { while($row_depto = mysql_fetch_assoc($rs_depto)) { ?> if(cod_area=='<?=$row_depto["id"]?>') { document.miformulario.modelo.options[indice] = new Option("<?=$row_depto["modelo"]?>","<?=$row_depto["id"]?>","defaultSelected","1"); document.miformulario.precioc.options[indice] = new Option("<?=$row_depto["precioc"]?>","<?=$row_depto["id"]?>","defaultSelected","1"); indice++; } <? } } mysql_close($con); ?> } </script>