Ayuda con listas dependientes

Te quiero pedir ayuda sobre como trabajar con select dependientes. Te mando el código que uso y luego te explico a lo que aspiro:
<html>
<head>
<script>
function slctr(texto,valor)
{
this.texto = texto
this.valor = valor
}
var ano = new Array()
ano[0] = new slctr('- -Diponibles- -')
ano[1] = new slctr("2006",'mes06')
ano[2] = new slctr("2007",'mes07')
var mes08 = new Array()
mes08[0] = new slctr('- -Meses- -')
mes08[1] = new slctr("ENERO",null)
mes08[2] = new slctr("FEBRERO",null)
mes08[3] = new slctr("MARZO",null)
mes08[4] = new slctr("ABRIL",null)
mes08[5] = new slctr("MAYO",null)
mes08[6] = new slctr("JUNIO",null)
mes08[7] = new slctr("JULIO",null)
mes08[8] = new slctr("AGOSTO",null)
mes08[9] = new slctr("SETIEMBRE",null)
mes08[10] = new slctr("OCTUBRE",null)
mes08[11] = new slctr("NOVIEMBRE",null)
mes08[12] = new slctr("DICIEMBRE",null)
var mes09 = new Array()
mes09[0] = new slctr('- -Meses- -')
mes09[1] = new slctr("ENERO",null)
mes09[2] = new slctr("FEBRERO",null)
mes09[3] = new slctr("MARZO",null)
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
}
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<select name="select" onchange="slctryole(this,this.form.select2)">
<option>- - Seleccionar - -</option>
<option value="ano">Ano</option>
</select>
<BR><BR>
<select name="select2" onchange="slctryole(this,this.form.select3)">
<option>- - - - - -</option>
</select>
<BR><BR>
<select name="select3">
<option>- - - - - -</option>
</select>
<BR><BR>
<HR noshade>
<p align="center"></font><font face="Arial"><a HREF="ruta.HTML"><img src="img/bproximo.gif"
width="40" height="40" alt="Volver"></a></font><font SIZE="2"></p>
</form>
</body>
</html>
Te comento al ejecutar este código, voy seleccionando, el año, el mes que yo quiero, ¿y al final de la página coloco un enlace a una página que este localizada en el disco por el paso c:/proye/ano/mes, por ejemplo c:/proyec/2006/enero, la pregunta es como armo la url que le llamo ruta.html para me levante esta página?. He leído sobre manuales de javacsript, pero no le encuentro solución. Me podrías ayudar con código.

1 respuesta

Respuesta
1
Prueba esto:
<html>
<head>
<script>
var ruta_ano;
var ruta_mes;
var obj = getElementById("ruta");
function slctr(texto,valor)
{
this.texto = texto
this.valor = valor
}
var ano = new Array()
ano[0] = new slctr('- -Diponibles- -')
ano[1] = new slctr("2006",'mes06')
ano[2] = new slctr("2007",'mes07')
var mes08 = new Array()
mes08[0] = new slctr('- -Meses- -')
mes08[1] = new slctr("ENERO",null)
mes08[2] = new slctr("FEBRERO",null)
mes08[3] = new slctr("MARZO",null)
mes08[4] = new slctr("ABRIL",null)
mes08[5] = new slctr("MAYO",null)
mes08[6] = new slctr("JUNIO",null)
mes08[7] = new slctr("JULIO",null)
mes08[8] = new slctr("AGOSTO",null)
mes08[9] = new slctr("SETIEMBRE",null)
mes08[10] = new slctr("OCTUBRE",null)
mes08[11] = new slctr("NOVIEMBRE",null)
mes08[12] = new slctr("DICIEMBRE",null)
var mes09 = new Array()
mes09[0] = new slctr('- -Meses- -')
mes09[1] = new slctr("ENERO",null)
mes09[2] = new slctr("FEBRERO",null)
mes09[3] = new slctr("MARZO",null)
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
}
if (cual.name == "select")
ruta_ano = donde.options[m].value;
else
ruta_mes = donde.options[m].value;
obj.href = "c:/proyec/" + ruta_ano + "/" + ruta_mes;
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<select name="select" onchange="slctryole(this,this.form.select2)">
<option>- - Seleccionar - -</option>
<option value="ano">Ano</option>
</select>
<BR><BR>
<select name="select2" onchange="slctryole(this,this.form.select3)">
<option>- - - - - -</option>
</select>
<BR><BR>
<select name="select3">
<option>- - - - - -</option>
</select>
<BR><BR>
<HR noshade>
<p align="center"></font><font face="Arial"><a id="ruta" HREF="ruta.HTML"><img src="img/bproximo.gif"
width="40" height="40" alt="Volver"></a></font><font SIZE="2"></p>
</form>
</body>
</html>
No sé si funcionará pero el camino está marcado: te guardas el mes y el año en un par de variables, y cambias la ruta del enlace según su valor.
Ánimo!
HOLA DAVID: gracias por tus conocimientos y aporte de una solución, probaré el código corregido y si tengo problemas te volveré a consultar

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas