Sto utilizzando questo script per avere 3 select, di cui 2 dinamiche.
<script type="text/javascript">
/*
Script tratto dal libro "JavaScript and DHTML Cookbook"
Pubblicato da O'Reilly & Associates
Copyright 2003 Danny Goodman
Riprodurre questa nota per qualunque riutilizzo del codice.
Con aggiunte di modifiche.
*/
var regiondb = new Object()
regiondb["africa"] = [{value:"1", text:"Cairo"},
{value:"2", text:"Lagos"},
{value:"3", text:"Nairobi"},
{value:"4", text:"Pretoria"},
{value:"all", text:" Cairo Lagos Nairobi Pretoria"}];
regiondb["asia"] = [{value:"1", text:"Ankara"},
{value:"2", text:"Bangkok"},
{value:"3", text:"Pechino"},
{value:"4", text:"New Delhi"},
{value:"5", text:" Tokyo "},
{value:"all", text:" Ankara Bangkok Pechino New Delhi Tokyo"}];
regiondb["australia"] = [{value:"1", text:"Suva"},
{value:"2", text:"Sydney"},
{value:"2", text:" Suva Sydney"}];
function setCities(chooser) {
var newElem;
var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
var cityChooser = chooser.form.elements["città"];
while (cityChooser.options.length) {
cityChooser.remove(0);
}
var choice = chooser.options[chooser.selectedIndex].value;
var db = regiondb[choice];
newElem = document.createElement("option");
newElem.text = "Seleziona una città:";
newElem.value = "";
cityChooser.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;
cityChooser.add(newElem, where);
}
}
}
</script>
<select name="Regioni" onchange=" setCities(this)">
<option value="" selected="selected">Choose a Region</option>
<option value="africa">Africa</option>
<option value="asia">Asia</option>
<option value="australia">Australia</option>
<option value="all">tutti I continenti (*disponibili ) </option>
</select>
<select name="città">
<option value="" selected="selected">Select your choice: </option>
</select>
<input type=submit value="submit">
<input type=reset value="reset">
L’intenzione e’ avere 2 select dove selezionando un continente in automatico si aggiorna la seconda select contenete le citta’. Selezionando la select citta’ o le citta’ ottengo una lista di informazioni come ad esempio una lista di comuni o distretti uno sotto l’altro.
Potreste aiutarmi ?