Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/11/2012, 18:12
Avatar de El Cipote
El Cipote
 
Fecha de Ingreso: febrero-2006
Mensajes: 213
Antigüedad: 18 años, 2 meses
Puntos: 2
Respuesta: capturar valores de combos anidados con PHP

despues de una noche de trabajo pude encontre una solucion:


Código PHP:
<? 
$bd_host 
"localhost"
$bd_usuario "userdb"
$bd_password "passwdb"
$bd_base "mibase"
$con mysql_connect($bd_host$bd_usuario$bd_password); 
mysql_select_db($bd_base$con); 
$sql "SELECT * from empresas"
$rs mysql_query($sql$con); 
?> 
<html> 
<head> 
<title>Documento sin t&iacute;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> 
<? if(mysql_num_rows($rs)>0

while(
$row mysql_fetch_assoc($rs)) 

?> 
<option value="<?=$row["Id"]?>"><?=$row["descripcion"]?></option> 
<? 


?> 
</select></td> 
<td><select name="depto" id="depto"> 
<option>--seleccione--</option> 
</select></td> 
</tr> 
<tr> 
<td> </td> 
<td> </td> 
</tr> 
</table> 
</form> 
</body> 
</html> 
<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; 
<? 
$sql_depto 
"SELECT * from departamentos"
$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.depto.options[indice] = new Option("<?=$row_depto["nombre_depto"]?>","<?=$row_depto["Id_depto"]?>"); 
indice++; 

<? 


mysql_close($con); 
?> 


</script>
las tablas son
DEPARTAMENTOS, con los siguientes campos:
Id Id_depto nombre_depto

EMPRESAS, con los siguientes campos:
Id descripcion



me funciono... y deseo compartirla
__________________
Para alcanzar el éxito se requiere de tres cosas: Voluntad, Valor y Decisión.