Di javascript non ne capisco ma a logica ho eseguito questo che funziona apparte che non riesco a nascondere le select non selezionate ma, solo a guardarlo vedo che che è scritto sbagliato, troppe cose ripetute e troppo lungo per una funzione che mi sembra più semplice.
Questo il code html:
<form name="form">
Numero bambini:
<select name="campo_principale" onChange="aggiornaOpzioni();">
<option value="0">numero bambini</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
età:
<select name="campo_der" ></select>
<select name="campo_der1"></select>
<select name="campo_der2"></select>
</form>
e questo il javascript:
<script language="javascript">
function selezionaOpzioni(scelta) {
var campo_der = document.form.campo_der;
campo_der.options.length = 0;
var campo_der1 = document.form.campo_der1;
campo_der1.options.length = 0;
var campo_der2 = document.form.campo_der2;
campo_der2.options.length = 0;
if (scelta == "1") {
campo_der.options[campo_der.options.length] = new Option('1');
campo_der.options[campo_der.options.length] = new Option('2');
campo_der.options[campo_der.options.length] = new Option('3');
campo_der.options[campo_der.options.length] = new Option('4');
campo_der.options[campo_der.options.length] = new Option('5');
campo_der.options[campo_der.options.length] = new Option('6');
campo_der.options[campo_der.options.length] = new Option('7');
campo_der.options[campo_der.options.length] = new Option('8');
campo_der.options[campo_der.options.length] = new Option('9');
campo_der.options[campo_der.options.length] = new Option('10');
}
if (scelta == "2") {
campo_der.options[campo_der.options.length] = new Option('1');
campo_der.options[campo_der.options.length] = new Option('2');
campo_der.options[campo_der.options.length] = new Option('3');
campo_der.options[campo_der.options.length] = new Option('4');
campo_der.options[campo_der.options.length] = new Option('5');
campo_der.options[campo_der.options.length] = new Option('6');
campo_der.options[campo_der.options.length] = new Option('7');
campo_der.options[campo_der.options.length] = new Option('8');
campo_der.options[campo_der.options.length] = new Option('9');
campo_der.options[campo_der.options.length] = new Option('10');
campo_der1.options[campo_der1.options.length] = new Option('1');
campo_der1.options[campo_der1.options.length] = new Option('2');
campo_der1.options[campo_der1.options.length] = new Option('3');
campo_der1.options[campo_der1.options.length] = new Option('4');
campo_der1.options[campo_der1.options.length] = new Option('5');
campo_der1.options[campo_der1.options.length] = new Option('6');
campo_der1.options[campo_der1.options.length] = new Option('7');
campo_der1.options[campo_der1.options.length] = new Option('8');
campo_der1.options[campo_der1.options.length] = new Option('9');
campo_der1.options[campo_der1.options.length] = new Option('10');
}
if (scelta == "3") {
campo_der.options[campo_der.options.length] = new Option('1');
campo_der.options[campo_der.options.length] = new Option('2');
campo_der.options[campo_der.options.length] = new Option('3');
campo_der.options[campo_der.options.length] = new Option('4');
campo_der.options[campo_der.options.length] = new Option('5');
campo_der.options[campo_der.options.length] = new Option('6');
campo_der.options[campo_der.options.length] = new Option('7');
campo_der.options[campo_der.options.length] = new Option('8');
campo_der.options[campo_der.options.length] = new Option('9');
campo_der.options[campo_der.options.length] = new Option('10');
campo_der1.options[campo_der1.options.length] = new Option('1');
campo_der1.options[campo_der1.options.length] = new Option('2');
campo_der1.options[campo_der1.options.length] = new Option('3');
campo_der1.options[campo_der1.options.length] = new Option('4');
campo_der1.options[campo_der1.options.length] = new Option('5');
campo_der1.options[campo_der1.options.length] = new Option('6');
campo_der1.options[campo_der1.options.length] = new Option('7');
campo_der1.options[campo_der1.options.length] = new Option('8');
campo_der1.options[campo_der1.options.length] = new Option('9');
campo_der1.options[campo_der1.options.length] = new Option('10');
campo_der2.options[campo_der2.options.length] = new Option('1');
campo_der2.options[campo_der2.options.length] = new Option('2');
campo_der2.options[campo_der2.options.length] = new Option('3');
campo_der2.options[campo_der2.options.length] = new Option('4');
campo_der2.options[campo_der2.options.length] = new Option('5');
campo_der2.options[campo_der2.options.length] = new Option('6');
campo_der2.options[campo_der2.options.length] = new Option('7');
campo_der2.options[campo_der2.options.length] = new Option('8');
campo_der2.options[campo_der2.options.length] = new Option('9');
campo_der2.options[campo_der2.options.length] = new Option('10');
}
}
function aggiornaOpzioni(scelta){
var selezionato = document.form.campo_principale.selectedIndex;
var campo = document.form.campo_principale.options;
selezionaOpzioni(campo[selezionato].value);
}
</script>
Tengo a far notare che dovrei avere la possibilità di scelta di almeno 10 bambini e l'età fino a 10 anni ed in più se nessuna scelta bambini viene fatta le select età dovrebbero essere nascoste.
Grazie