Skript dyn. Listenfeld funktioniert erst nach "Neu laden"
Johannes
- javascript
Folgendes Skript erzeugt ein Listenfeld "areas" nachdem im Listenfeld
country onChange ausgelöst wird. Unter NS 4.x erscheint das Listenlfeld "areas" dann aber erst nach dem einmalig "Neu laden" angeklickt wurde.
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title></title>
</head>
<script language="javascript" >
function caselection(){
var de_areas = new Array();
de_areas["de1"] = "Baden-Württemberg";
de_areas["de2"] = "Bayern";
de_areas["de3"] = "Berlin";
de_areas["de4"] = "Brandenburg";
de_areas["de5"] = "Bremen";
de_areas["de6"] = "Hamburg";
de_areas["de7"] = "Hessen";
de_areas["de8"] = "Mecklenburg-Vorp.";
de_areas["de9"] = "Niedersachsen";
de_areas["de10"]= "Nordrhein-Westfalen";
de_areas["de11"]= "Rheinland-Pfalz";
de_areas["de12"]= "Saarland";
de_areas["de13"]= "Sachsen";
de_areas["de14"]= "Sachsen-Anhalt";
de_areas["de15"]= "Schleswig-Holstein";
de_areas["de16"]= "Thüringen";
var at_areas = new Array();
at_areas["at1"] = "Burgenland";
at_areas["at2"] = "Kärnten";
at_areas["at3"] = "Niederösterreich";
at_areas["at4"] = "Salzburg";
at_areas["at5"] = "Steiermark";
at_areas["at6"] = "Tirol";
at_areas["at7"] = "Vorarlberg";
at_areas["at8"] = "Wien";
var ch_areas = new Array();
ch_areas["ch1"] = "Aargau";
ch_areas["ch2"] = "Appenzell-Ausser-Rhoden";
ch_areas["ch3"] = "Appenzell-Inner-Rhoden";
ch_areas["ch4"] = "Basel-Land";
ch_areas["ch5"] = "Basel-Stadt";
ch_areas["ch6"] = "Bern";
ch_areas["ch7"] = "Fribourg";
ch_areas["ch8"] = "Genf";
ch_areas["ch9"] = "Glarus";
ch_areas["ch10"] = "Graubünden";
ch_areas["ch11"] = "Jura";
ch_areas["ch12"] = "Luzern";
ch_areas["ch13"] = "Neuchatel";
ch_areas["ch14"] = "Nidwalden";
ch_areas["ch15"] = "Obwalden";
ch_areas["ch16"] = "Schaffhausen";
ch_areas["ch17"] = "Schwyz";
ch_areas["ch18"] = "Solothurn";
ch_areas["ch19"] = "St. Gallen]";
ch_areas["ch20"] = "Thurgau";
ch_areas["ch21"] = "Tessin/Ticino";
ch_areas["ch22"] = "Uri";
ch_areas["ch23"] = "Vaud/Waadt";
ch_areas["ch24"] = "Valais/Wallis";
ch_areas["ch25"] = "Zug";
ch_areas["ch26"] = "Zürich";
c=document.forms['CountriesAreasSearch'].elements['country'];
if (c[c.selectedIndex].value=="de"){
counter = 0;
box = document.forms['CountriesAreasSearch'].elements['areas'];
while (box.options.length) box.options[0] = null;
for (i in de_areas){
NewItem = new Option(de_areas[i],i,false,false);
document.forms['CountriesAreasSearch'].elements['areas'].options[counter] = NewItem;
counter = counter + 1;
}
}
if (c[c.selectedIndex].value=="at"){
counter = 0;
box = document.forms['CountriesAreasSearch'].elements['areas'];
while (box.options.length) box.options[0] = null;
document.forms['CountriesAreasSearch'].elements['areas'].options.length=0;
for (i in at_areas){
NewItem = new Option(at_areas[i],i,false,false);
document.forms['CountriesAreasSearch'].elements['areas'].options[counter] = NewItem;
counter = counter + 1;
}
}
if (c[c.selectedIndex].value=="ch"){
counter = 0;
box = document.forms['CountriesAreasSearch'].elements['areas'];
while (box.options.length) box.options[0] = null;
for (i in ch_areas){
NewItem = new Option(ch_areas[i],i,false,false);
document.forms['CountriesAreasSearch'].elements['areas'].options[counter] = NewItem;
counter = counter + 1;
}
}
}
</script>
<body bgcolor="#ffffff">
<form name="CountriesAreasSearch" method="post" action="test.php4">
<select name="country" size="1" onChange="caselection()">
<option value="de">Deutschland</option>
<option value="ch">Schweiz</option>
<option value="at">Österreich</option>
</select>
<br><br>
<select name="areas" size="1" value=""><option>---</option></select>
</form>
</body>
</html>