Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    select dinamiche -scovare l'errore-

    dunque, avevo bisogno di fare una semplice select dinamica cosi' googolando ho trovato un esempio semplice che usa javascript. ma nel mio codice c'e' qualche problema che non riesco a scovare.
    posto l'originale funzionante ed il mio.
    grazie per l'aiuto

    codice:
     
    
    
    <script type="text/javascript">
    
    var shipping = new Object()
    shipping["1"] = [{value:"1", text:"Carta di credito"},
                          {value:"2", text:"contrassegno"},
                          {value:"3", text:"Bollettino postale"}];
    shipping["2"] = [{value:"1", text:"Carta di credito"},
                          {value:"4", text:"bonifico bancario"}];
    shipping["3"] = [{value:"1", text:"Carta di credito"},
                          {value:"4", text:"bonifico bancario"}];
    
    function setCost(chooser) {
        var newElem;
        var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
        var costChooser = chooser.form.elements["id_pag"];
        while (costChooser.options.length) {
            costChooser.remove(0);
        }
        var choice = chooser.options[chooser.selectedIndex].value;
        var db = shipping[choice];
        newElem = document.createElement("option");
        newElem.text = "tipo di pagamento:";
        newElem.value = "";
        costChooser.add(newElem, where);
        if (choice != "") {
            for (var i = 0; i < db.length; i++) {
                newElem = document.createElement("option");
                newElem.text = db[i].text;
                newElem.value = db[i].value;
                costChooser.add(newElem, where);
            }
        }
    }
    
    </script>
    <form action="" method="post" name="frmCart" id="frmCart">
    <select name="id_area" onchange="setCost(this)">
    <option value="" selected="selected">Seleziona un area</option>
    
    <option value="1">Italia</option>
    <option value="2">Europa e bacino del Mediterraneo</option>
    <option value="3">Paesi extra europei</option>
    </select>
    </td></tr>
    <tr><td colspan="8">
    <select name="id_pag" onchange="this.form.submit();">
    <option value="" selected="selected">Seleziona il tipo di pagamento</option>
    </select>
    
    </form>

    codice:
    <script type="text/javascript">
    var dati = new Objetc() 
    dati["2010-06-26"] = [ {value:"0", text:"08:00:00"} ];
    dati["2010-06-27"] = [ {value:"1", text:"08:20:00"}, {value:"2", text:"08:00:00"} ];
    dati["2010-06-28"] = [ {value:"3", text:"08:20:00"} ];
    dati["2010-08-28"] = [ {value:"4", text:"21:20:00"} ];
    
    function setSlot(chooser) {
    	var newElem;
    	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 :	null; 
    	var slotChooser = chooser.form.elements["slot"];
    	while (slotChooser.options.length) {
    		slotChooser.remove(0);
    	}
    	var choice = chooser.options[chooser.selectedIndex].value;
    	var db = dati[choice];
    	newElem = document.createElement("option");
    	newElem.text = "seleziona uno slot:";
    	newElem.value = "";
    	slotChooser.add(newElem, where);
    	if (choice != "") {
    		for (var i = 0; i < db.length; i++) {
    			newElem = document.createElement("option");
    			newElem.text = db[i].text;
    			newElem.value = db[i].value;
    			slotChooser.add(newElem, where);
    		}
    	}
    }
      
    
    </script>
    <table>
     <form action="" method="post" name="frmCart" id="frmCart">
    Data:
    <select name="data" onchange="setSlot(this)">
    <option value="" selected="selected">data</option>
    <option value="2010-06-26">2010-06-26</option>
    <option value="2010-06-27">2010-06-27</option>
    <option value="2010-06-27">2010-06-27</option>
    <option value="2010-06-28">2010-06-28</option>
    
    <option value="2010-08-28">2010-08-28</option>
    
    </select>
    </td></tr>
    <tr><td colspan="8">
    Slot:
    <select name="slot" onchange="this.form.submit();">
    <option value="" selected="selected">Seleziona uno slot</option>
    </select>
    </form>
    </table>

  2. #2
    seconda riga del tuo codice:
    codice:
    var dati = new Objetc()

  3. #3
    grazie per la celere risposta! sarà stata l'ora tarda comunque avevo risolto cambiando Object() con Array()

    gia' che ci sono, un editor per javascript che mi evidenzi certi tipi di errore?
    sempre se e' un controllo fattibile...?

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.