Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Select dinamica

  1. #1

    Select dinamica

    Ciao.

    E' possibile far si che da una select, compia successivamente un0altra porzione di codice?

    Mi spiego meglio: ho un campo select con le opzioni 1 e 2. Se scelgo 1 mi appare un altro campo select con determinati valori, se invece scelgo due mi appare un campo di testo.


    E' possibile? se si come? thx so much
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  2. #2
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    Sì, è possibile...

    Devi semplicemente gestire l'evento onchange della select attribuendogli una funzione che effettui il controllo dell'indice/valore selezionato. In base a questo poi crei la seconda select o il campo di testo. In alternativa, anziché creare i due elementi dinamicamente, gestisci la visibilità (visibility) o il display dell'elemento tramite javascript e css.

  3. #3
    perfettop ho trovato questa funzione che però lo fa con un link! La devo cambiare in select...come faccio?

    codice:
    if(document.getElementById && document.createElement){
    document.write('<style type="text/css">*.toggle{display:none}</style>');
    window.onload=function(){
        /*le modifiche allo script vanno solo fatte qui*/
        Attiva("versa","Versa in Cassa","Versa in Cassa");
        Attiva("preleva","Preleva dalla Cassa","Preleva dalla Cassa");
        }
    }
    
    function Attiva(id,s1,s2){
    var el=document.getElementById(id);
    el.style.display="none";
    var c=document.createElement("div");
    var link=document.createElement("a");
    link.href="#";
    link.appendChild(document.createTextNode(s1));
    link.onclick=function(){
        link.firstChild.nodeValue = (link.firstChild.nodeValue==s1) ? s2 : s1;
        el.style.display=(el.style.display=="none") ? "block" : "none";
        return(false);
        }
    link.onfocus=this.blur();
    c.appendChild(link);
    el.parentNode.insertBefore(c,el);
    }
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  4. #4
    per ora sono riuscito ad adattare la porzione di codice nella select..


    codice:
    <select name="B" class='BTN' onChange="if(this.options[1].selected) Attiva(id1); else if(this.options[2].selected) Attiva(id2); ">

    ma la funzione non so proprio modificarla...
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  5. #5
    help me if you can..
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  6. #6
    Utente di HTML.it L'avatar di hcka
    Registrato dal
    Oct 2002
    Messaggi
    435
    Esempio:

    codice:
        [...]
        <script>
          function controllaScelta(indiceSelezionato)
          {
            switch(indiceSelezionato)
            {
              case 1:
                var
                  newElement = document.createElement("select"),
                  opt1 = document.createElement("option"),
                  opt2 = document.createElement("option"),
                  opt3 = document.createElement("option");
                newElement.setAttribute("name", "nomeSelect");
                opt1.appendChild(document.createTextNode("Select dinamica opzione 1"));
                opt2.appendChild(document.createTextNode("Select dinamica opzione 2"));
                opt3.appendChild(document.createTextNode("Select dinamica opzione 3"));
                newElement.appendChild(opt1);
                newElement.appendChild(opt2);
                newElement.appendChild(opt3);
              break;
              case 2:
                var
                  newElement = document.createElement("input");
                newElement.setAttribute("type", "text");
                newElement.setAttribute("name", "nomeCampo");
              break;
              default:
              break;
            }
            document.getElementById("asd").appendChild(newElement);
          }
        </script>
      </head>
      <body>
        <div id="asd">
          <select onchange="controllaScelta(this.selectedIndex);">
            <option value="0">--- seleziona ---</option>
            <option value="1">Scelta per altra select</option>
            <option value="2">Scelta per input text</option>
          </select>
        </div>
        [...]
    Poi devi settare tutti gli attributi necessari/che ti occorrono alla select ed al campo di testo...

    Fammi sapere se ti funziona...

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.