Código PHP :
<?php
$bd_host = "localhost";
$bd_usuario = "root";
$bd_password = "";
$bd_base = "sistema_ventas";
$con = mysql_connect($bd_host, $bd_usuario, $bd_password);
mysql_select_db($bd_base, $con);
$sql = "SELECT * from tipo_servicio";
$rs = mysql_query($sql, $con);
?>
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>Seleccion de un select y cambiar los valores de otro select sin tener que submitar (valido segun su uso)</p>
<form name="miformulario" method="get">
<table width="249" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Empresa</td>
<td>Departamento</td>
</tr>
<tr>
<td><select name="empresa" id="empresa" onChange="componer_Centros(this.value)">
<option value="">--Seleccione--</option>
<?php if(mysql_num_rows($rs)>0)
{
while($row = mysql_fetch_assoc($rs))
{
?>
<option value="<?=$row["id_tipo_serv"]?>"><?=$row["descripcion"]?></option>
<?php
}
}
?>
</select></td>
<td><select name="depto" id="depto" onChange="componer_Centros1(this.value)">
<option>--seleccione--</option>
</select></td>
</tr>
<tr>
<td><select name="depto1" id="depto1">
<option>--seleccione--</option>
</select></td>
<td> </td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
<script>
function filtrar3()
{
var seleccion=document.getElementById('depto');
document.getElementById('pago').value=seleccion.options[seleccion.selectedIndex].text;
}
</script>
<script>
function componer_Centros(cod_area)
{
//alert(cod_area);
document.miformulario.depto.length=0;
document.miformulario.depto.options[0] = new Option("-- Seleccione --","","defaultSelected","");
var indice=1;
<?php
$sql_depto = "SELECT * from servicio";
$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_tipo_serv"]?>')
{
document.miformulario.depto.options[indice] = new Option("<?=$a=$row_depto["nombre"]?>","<?=$b=$row_depto["id_servicio"]?> ");
indice++;
}
<?php
}
}
?>
}
</script>
<script>
function componer_Centros1(cod_area1)
{
//alert(cod_area);
document.miformulario.depto1.length=0;
document.miformulario.depto1.options[0] = new Option("-- Seleccione --","","defaultSelected","");
var indice1=1;
<?php
$sql_depto1 = "SELECT * from servicio";
$rs_depto1 = mysql_query($sql_depto1, $con);
if(mysql_num_rows($rs_depto1)>0)
{
while($row_depto1 = mysql_fetch_assoc($rs_depto1))
{
?>
if(cod_area1=='<?=$row_depto1["id_servicio"]?>')
{
document.miformulario.depto1.options[indice1] = new Option("<?=$c=$row_depto1["nombre"]?>","<?=$d=$row_depto1["id_servicio"]?> ");
indice1++;
}
<?php
}
}
mysql_close($con);
?>
}
</script>
<body>
<input name="pago" id="pago" type="text">
</body>
este es mi código no se como hacer que parezca un tercer combo dependiendo del segundo pero este ultimo es de la misma tabla.
