codice:
<script type="text/javascript">
/*
Script tratto dal libro "JavaScript and DHTML Cookbook" - Capitolo 8-13
Pubblicato da O'Reilly & Associates
Copyright 2003 Danny Goodman
Riprodurre questa nota per qualunque riutilizzo del codice.
*/
var regiondb = new Object()
regiondb["africa"] = [{value:"102", text:"Cairo"},
{value:"88", text:"Lagos"},
{value:"80", text:"Nairobi"},
{value:"55", text:"Pretoria"}];
regiondb["asia"] = [{value:"30", text:"Ankara"},
{value:"21", text:"Bangkok"},
{value:"49", text:"Pechino"},
{value:"76", text:"New Delhi"},
{value:"14", text:"Tokyo"}];
regiondb["australia"] = [{value:"64", text:"Suva"},
{value:"12", text:"Sydney"}];
regiondb["europa"] = [{value:"11", text:"Atene"},
{value:"35", text:"Francoforte"},
{value:"3", text:"Londra"},
{value:"15", text:"Madrid"},
{value:"1", text:"Parigi"},
{value:"10", text:"Roma"},
{value:"6", text:"Stoccolma"},
{value:"97", text:"San Pietroburgo"}];
regiondb["noamer"] = [{value:"73", text:"Dallas"},
{value:"71", text:"Los Angeles"},
{value:"5", text:"New York"},
{value:"37", text:"Toronto"}];
regiondb["suamer"] = [{value:"65", text:"Buenos Aires"},
{value:"31", text:"Caracas"},
{value:"66", text:"Rio di Janeiro"}];
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>
preso proprio da html.it
codice:
var giornidb = new Object()
giornidb["Aprile 2005","Giugno 2005","Settembre 2005"] = [{value:"1", text:"1"},
{value:"2", text:"2"},
{value:"3", text:"3"},
{value:"4", text:"4"},
{value:"5", text:"5"},
{value:"6", text:"6"},
{value:"7", text:"7"},
{value:"8", text:"8"},
{value:"9", text:"9"},
{value:"10", text:"10"},
{value:"11", text:"11"},
{value:"12", text:"12"},
{value:"13", text:"13"},
{value:"14", text:"14"},
{value:"15", text:"15"},
{value:"16", text:"16"},
{value:"17", text:"17"},
{value:"18", text:"18"},
{value:"19", text:"19"},
{value:"20", text:"20"},
{value:"21", text:"21"},
{value:"22", text:"22"},
{value:"23", text:"23"},
{value:"24", text:"24"},
{value:"25", text:"25"},
{value:"26", text:"26"},
{value:"27", text:"27"},
{value:"28", text:"28"},
{value:"29", text:"29"},
{value:"30", text:"30"}];
giornidb["Maggio 2005","Luglio 2005","Agosto 2005","Ottobre 2005"] = [{value:"1", text:"1"},
{value:"2", text:"2"},
{value:"3", text:"3"},
{value:"4", text:"4"},
{value:"5", text:"5"},
{value:"6", text:"6"},
{value:"7", text:"7"},
{value:"8", text:"8"},
{value:"9", text:"9"},
{value:"10", text:"10"},
{value:"11", text:"11"},
{value:"12", text:"12"},
{value:"13", text:"13"},
{value:"14", text:"14"},
{value:"15", text:"15"},
{value:"16", text:"16"},
{value:"17", text:"17"},
{value:"18", text:"18"},
{value:"19", text:"19"},
{value:"20", text:"20"},
{value:"21", text:"21"},
{value:"22", text:"22"},
{value:"23", text:"23"},
{value:"24", text:"24"},
{value:"25", text:"25"},
{value:"26", text:"26"},
{value:"27", text:"27"},
{value:"28", text:"28"},
{value:"29", text:"29"},
{value:"30", text:"30"},
{value:"30", text:"31"}];
function setGiorni1(chooser) {
if (
var newElem;
var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
var dayChooser = chooser.form.elements[tipo];
while (dayChooser.options.length) {
dayChooser.remove(0);
}
var choice = chooser.options[chooser.selectedIndex].value;
var db = giornidb[choice];
if (choice != "") {
for (var i = 0; i < db.length; i++) {
newElem = document.createElement("option");
newElem.text = db[i].text;
newElem.value = db[i].value;
dayChooser.add(newElem, where);
}
}
}
</script>
Mi date una mano?