Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Script da "legare"

  1. #1
    Membro Senior
    Registrato dal
    Mar 2003
    Messaggi
    68

    Script da "legare"

    Salve,
    ho qst codice:

    <script language="JavaScript" type="text/JavaScript">
    function Cambia(valore) {
    modulo=document.form; switch(valore) {
    case '1':
    modulo.B.options[0]=new Option('testo1a','valore1a');
    modulo.B.options[1]=new Option('testo1b','valore1b');
    modulo.B.options[2]=new Option('testo1c','valore1c');
    break;
    case '4':
    modulo.B.options[0]=new Option('testo2a','valore2a');
    modulo.B.options[1]=new Option('testo2b','valore2b');
    modulo.B.options[2]=new Option('testo2c','valore2c');
    break;
    case '5':
    modulo.B.options[0]=new Option('testo3a','valore3a');
    modulo.B.options[1]=new Option('testo3b','valore3b');
    modulo.B.options[2]=new Option('testo3c','valore3c');
    break;
    }
    }
    </script>
    <body>

    <form name="form" method="get" action="top_dx.php" target="rightFrame">
    <table width="337">
    <tr>
    <td>Città:
    <select name="A" onChange="Cambia(this[this.selectedIndex].value);">





    <option value="%">Tutte le città</option>
    <option value="1">Rovigo</option>
    <option value="4">Milano</option>
    <option value="5">Milano</option>
    <option value="6">Torino</option>
    <option value="7">Roma</option>
    <option value="8">Veneziaa</option>
    <option value="10">Berlino</option>
    <option value="11">amsterdam</option>
    </select>
    </td>
    <td>
    <select name="B">
    </select>
    </td>

    <td> </td>
    </tr>
    </table>
    </form>
    </body>
    </html>



    ke dovrebbe combiaciare con qst'altro:


    <script language="JavaScript">

    function Sposta(cosa) {
    var contenitore=document.mioform.contenitore;
    var quanti=contenitore.options.length;
    var trovato=false;
    for (i=0; i<quanti; i++) if (contenitore[i].value==cosa) trovato=true;
    if (cosa!="Nulla" && !trovato)
    contenitore.options[quanti]=new Option(cosa,cosa);
    }

    function Cancella(myform) {
    var elementi=myform.contenitore.options;
    var valori=new Array();
    var testi=new Array();
    for (i=0; i<elementi.length; i++)
    if (elementi[i].selected) break;
    k=0;
    for (j=0; j<elementi.length; j++) {
    if (i!=j) {
    valori[k]=elementi[j].value;
    testi[k]=elementi[j].text;
    k++
    }
    }
    for (i=0; i<valori.length; i++) {
    myform.contenitore.options[i]=new Option(valori[i], testi[i]);
    }
    myform.contenitore.options.length=valori.length;
    }

    </script>

    </head>

    <body>
    <form name="mioform">
    <select name="prodotti" onChange="Sposta(this[this.selectedIndex].value);">
    <option value="Nulla" selected></option>
    <option value="Pesce">Pesce</option>
    <option value="Carne">Carne</option>
    <option value="Frutta">Frutta</option>
    </select>


    <font size="2" face="Tahoma">Lista prodotti: </font>


    <select name="contenitore" size="5">
    </select>
    <input type="button" name="Submit" value="Cancella" onClick="Cancella(this.form);">
    </form>




    <div id="livello"></div>
    </body>
    </html>

    il primo preso da 1 post sul forum l'altro mi è stato creato apposta.
    ma adexo vorrei ke il primo codice combaciaxe con il secondo, oxia:
    ke qnd dal secondo menù a discesa si fà 1 scelta, qst venixe automaticamente spostata nel livello del secondo codice (e cioè ke il menù a discesa del secondo codice contenexe già dei dati provenineti dal primo.

    mi aiutate xfavore?
    tx a tutti in anticipo

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    633
    ciao n@sky, scusa ma io non ho capito bene cosa vorresti fare...cosa dovrebbe cambiare nel secondo script?
    Alcuni miei articoli in PRO.HTML.IT: JavaScript | DHTML | DOM
    Sviluppo : wedev | forum

  3. #3
    Membro Senior
    Registrato dal
    Mar 2003
    Messaggi
    68
    nn nel secondo script, ma nel primo: dovrebbe exere legato al secondo in modo ke la scelta del primo menù cada nel secondo ke poi cadrà nel contenitore ke stà nel secondo script

  4. #4
    Reale_Augello
    Guest

    Ecco...

    ... qui:

    codice:
    <html>
    <head>
    <script language="JavaScript" type="text/JavaScript"> 
    function Cambia(valore) { 
    modulo=document.form; switch(valore) { 
    case '1': 
    modulo.B.options[0]=new Option('testo1a','valore1a'); 
    modulo.B.options[1]=new Option('testo1b','valore1b'); 
    modulo.B.options[2]=new Option('testo1c','valore1c'); 
    break; 
    case '4': 
    modulo.B.options[0]=new Option('testo2a','valore2a'); 
    modulo.B.options[1]=new Option('testo2b','valore2b'); 
    modulo.B.options[2]=new Option('testo2c','valore2c'); 
    break; 
    case '5': 
    modulo.B.options[0]=new Option('testo3a','valore3a'); 
    modulo.B.options[1]=new Option('testo3b','valore3b'); 
    modulo.B.options[2]=new Option('testo3c','valore3c'); 
    break; 
    } 
    } 
    
    function Cancella(myform) {
     var elementi=myform.contenitore.options;
     var valori=new Array();
     var testi=new Array();
     for (i=0; i<elementi.length; i++)
      if (elementi[i].selected) break;
     k=0;
     for (j=0; j<elementi.length; j++) {
      if (i!=j) {
       valori[k]=elementi[j].value;
       testi[k]=elementi[j].text;
       k++
      }
     }
     for (i=0; i<valori.length; i++) {
      myform.contenitore.options[i]=new Option(valori[i], testi[i]);
     }
     myform.contenitore.options.length=valori.length;
    }
    
    function Sposta(cosa) {
     var contenitore=document.form.contenitore;
     var quanti=contenitore.options.length;
     var trovato=false;
     for (i=0; i<quanti; i++) if (contenitore[i].value==cosa) trovato=true;
     if (cosa!="Nulla" && !trovato)
     contenitore.options[quanti]=new Option(cosa,cosa);
    }
    
    </script> 
    </head>
    <body> 
    
    <form name="form" method="get" action="top_dx.php" target="rightFrame"> 
    <table width="337"> 
    <tr> 
    <td>Città: 
    <select name="A" onChange="Cambia(this[this.selectedIndex].value);"> 
    
    
     
     
    
    <option value="%">Tutte le città</option> 
    <option value="1">Rovigo</option> 
    <option value="4">Milano</option> 
    <option value="5">Milano</option> 
    <option value="6">Torino</option> 
    <option value="7">Roma</option> 
    <option value="8">Veneziaa</option> 
    <option value="10">Berlino</option> 
    <option value="11">amsterdam</option> 
    </select> 
    </td> 
    <td> 
    <select name="B" onChange="Sposta(this[this.selectedIndex].value);"> 
    </select> 
    </td> 
    
    <td> </td> 
    </tr> 
    </table> 
    
      <select name="contenitore" size="5">
      </select>
      <input type="button" name="Submit" value="Cancella" onClick="Cancella(this.form);">
    </form> 
    </body> 
    </html>
    Ciao !

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    633
    Originariamente inviato da n@sky
    nn nel secondo script, ma nel primo: dovrebbe exere legato al secondo in modo ke la scelta del primo menù cada nel secondo ke poi cadrà nel contenitore ke stà nel secondo script
    ...io provo ad interpretare...

    codice:
    <html>
    <head>
    <title> ciao</title>
    <script language="JavaScript" type="text/JavaScript"> 
    
    function Aggiungi(valore){
    	var modulo=document.form, l=modulo.B.options.length,i;
    	for(i=0; i<l; i++) if(modulo.B.options[i].value==valore||valore=="%") return;
    	modulo.B.options[l] = new Option(valore,valore);
    }
    </script> 
    </HEAD>
    <body> 
    
    <form name="form" method="get" action="top_dx.php" target="rightFrame"> 
    <table width="337"> 
    <tr> 
    <td>Città: 
    <select name="A" onChange="Aggiungi(this[this.selectedIndex].value);"> 
    
    
    <option value="%">Tutte le città</option> 
    <option value="Rovigo">Rovigo</option> 
    <option value="Milano">Milano</option> 
    <option value="Torino">Torino</option> 
    <option value="Roma">Roma</option> 
    <option value="Venezia">Venezia</option> 
    </select> 
    </td> 
    <td> 
    <select name="B"> 
    </select> 
    </td> 
    
    <td> </td> 
    </tr> 
    </table> 
    </form> 
    </body> 
    </html>
    vedi se è quello che vorresti...
    Alcuni miei articoli in PRO.HTML.IT: JavaScript | DHTML | DOM
    Sviluppo : wedev | forum

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    633
    beh..ora hai due possibilità..qualcuno c'avrà preso

    ciauzz
    Alcuni miei articoli in PRO.HTML.IT: JavaScript | DHTML | DOM
    Sviluppo : wedev | forum

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    1,965

  8. #8
    Membro Senior
    Registrato dal
    Mar 2003
    Messaggi
    68
    tx Reale, il tuo codice è xfetto!
    tx mitico, 6 1 grande!







    p.s. standard anke il tuo codice è buono, ma a me serviva il contenitore del 2° script, ke xò nel tuo codice nn c'è +.




    cmq tx ad entrambi, siete stati come sempre fantastici.

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.