Estoy haciendo un form con combobox anidados y encontre este que funciona al 100% pero necesito agragarle tres textbox que funcionen de la siguiente manera: al ingresar el segundo textbox me tiene que guardar el id del primer combobox elegido en ese momento, pues ese segundo textbox será una subcategoria del primer combobox e igual con el tercer textbox solo que con el id del segundo combobox. Alguien sabe como podría obtener ese id segun lo que se escoja... Gracias :)
Código PHP:
<!--
function slctr(texto,valor){
this.texto = texto
this.valor = valor
}
function slctryole(cual,donde){
if(cual.selectedIndex != 0){
donde.length=0
cual = eval(cual.value)
for(m=0;m<cual.length;m++){
var nuevaOpcion = new Option(cual[m].texto);
donde.options[m] = nuevaOpcion;
if(cual[m].valor != null){
donde.options[m].value = cual[m].valor
}
else{
donde.options[m].value = cual[m].texto
}
}
}
}
<?
$query = mysql_query("select * from categorias_productos order by id_categoria_padre");
$categorias_padre = array();
while($res = mysql_fetch_assoc($query)){
$contador = 0;
if($res["id_categoria_padre"] == 0) $categorias_padre["cat_".$res["id_categoria"]] = $res["nombre_categoria"];
?>
var cat_<?=$res["id_categoria"] ?>=new Array()
cat_<?=$res["id_categoria"]."[".$contador++ ?>] = new slctr('- -<?=$res["nombre_categoria"] ?>- -')
<?
if($res["id_categoria_padre"] == 0){
$query2 = mysql_query("select id_categoria, nombre_categoria as 'nombre' from categorias_productos where id_categoria_padre = ". $res["id_categoria"]. " order by nombre_categoria");
}
else{
$query2 = mysql_query("select id_categoria, nombre_producto as 'nombre' from productos where id_categoria = ". $res["id_categoria"]. " order by nombre_producto");
}
while($res2 = mysql_fetch_assoc($query2)){ ?>
cat_<?=$res["id_categoria"]."[".$contador++ ?>] = new slctr("<?=$res2["nombre"]?>",'cat_<?=$res2["id_categoria"]?>')
<? }
}
?>
//-->
</script>
</head>
<body>
<form>
<fieldset>
<select name="select" onchange="slctryole(this,this.form.select2)">
<option>- - Seleccionar - -</option>
<?
foreach($categorias_padre as $idd =>$cat){ ?>
<option value="<?=$idd?>"><?=$cat?></option>
<?
}
?>
</select>
<select name="select2" onchange="slctryole(this,this.form.select3)">
<option>- - - - - -</option>
</select>
<select name="select3">
<option>- - - - - -</option>
</select>
<input type="hidden" name="id_cat" id="id_cat" value=""/>
<input type="text" name="nombre_cat" id="nombre_cat" value=""/>
<input type="hidden" name="id_cat_padre" id="id_cat_padre" value="0"/>
<input type="hidden" name="id_cat2" id="id_cat" value=""/>
<input type="text" name="nombre_cat2" id="nombre_cat" value=""/>
<input type="hidden" name="id_cat_padre2" id="id_cat_padre" value=""/>
<input type="hidden" name="id_cat3" id="id_cat3" value=""/>
<input type="text" name="categoria_3" id="categoria_3" value=""/>
<input type="hidden" name="id_cat" id="id_cat" value=""/>
</fieldset>
</form>
</body>
</html>