Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174

    select che apre altre select

    Non sò se ho postato giusto quì ma, da una ricerca che ho fatto mi sembrava che serve il javascript.

    In un form devo mettere una select che sceglie quante persone.
    In base alla selezione 1,2,3.... apre altre select tante quante la selezione, per inserire l'età dei precedenti.

    3 persone apre 3 select
    4 persone apre 4 select e così via

    Logicamente se alla prima select non seleziono nulla non si aprono le successive.

    La pagina è in asp.

    Grazie
    Pattaya

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Vedi se questa discussione ti è d'aiuto.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174
    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
    Pattaya

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.