En el código que muestro más abajo, se rellena el campo secundario select según la opción del primer campo select.
![lloron](http://static.forosdelweb.com/fdwtheme/images/smilies/chillando.png)
<select name="modalidad" onChange="anade()">
<option value=""></option>
<option value="1">opcion 1</option>
<option value="2">opcion 2</option>
<option value="3">opcion 3</option>
<option value="4">opcion 4</option>
</select>
<select name="sele"></select>
[/HTML]
Bueno ahora viene el javascript
Código HTML:
<script language="javascript" type="text/javascript"> <!-- function anade() { if (document.datos.modalidad[1].selected) { document.datos.sele[0]= new Option("",""); document.datos.sele[1]= new Option("opcion 1.1","opcion 1.1"); document.datos.sele[2]= new Option("opcion 1.2","opcion 1.2"); document.datos.sele[3]= new Option("opcion 1.3","opcion 1.3"); document.datos.sele[4]= new Option("opcion 1.4","opcion 1.4"); document.datos.sele[5]= new Option("opcion 1.5","opcion 1.5"); document.datos.sele[6]= new Option("opcion 1.6","opcion 1.6"); document.datos.sele[7]= new Option("opcion 1.7","opcion 1.7"); } if (document.datos.modalidad[2].selected) { document.datos.sele[0]= new Option("",""); document.datos.sele[1]= new Option("opcion 2.1","opcion 2.1"); document.datos.sele[2]= new Option("opcion 2.2","opcion 2.2"); document.datos.sele[3]= new Option("opcion 2.3","opcion 2.3"); document.datos.sele[4]= new Option("opcion 2.4","opcion 2.4"); document.datos.sele[5]= new Option("opcion 2.5","opcion 2.5"); document.datos.sele[6]= new Option("opcion 2.6","opcion 2.6"); } if (document.datos.modalidad[3].selected) { document.datos.sele[0]= new Option("",""); document.datos.sele[1]= new Option("opcion 3.1","opcion 3.1"); document.datos.sele[2]= new Option("opcion 3.2","opcion 3.2"); document.datos.sele[3]= new Option("opcion 3.3","opcion 3.3"); } if (document.datos.modalidad[4].selected) { document.datos.sele[0]= new Option("",""); document.datos.sele[1]= new Option("opcion 4.1","opcion 4.1"); } } --> </script>
opciones ... Lo malo es que cuando carga una la primera opcion carga sus siete opciones, pero si seleccionamos la cuarta opcion que
solo tiene una opcion (cuantas opciones
![dormir](http://static.forosdelweb.com/fdwtheme/images/smilies/durmiendo.png)
carga seis más hasta llenar a siete.
¿Qué se podría hacer para que antes de que se llene el select ?
¿Se puede vaciar el select antes de llenarlo otra vez? pero como
![lloron](http://static.forosdelweb.com/fdwtheme/images/smilies/chillando.png)
![lloron](http://static.forosdelweb.com/fdwtheme/images/smilies/chillando.png)
![Neurótico](http://static.forosdelweb.com/fdwtheme/images/smilies/scared.png)
![Neurótico](http://static.forosdelweb.com/fdwtheme/images/smilies/scared.png)