Prøv om du kan bruge flg. til noget
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>TEST</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="
http://schemas.microsoft.com/intellisense/ie5"> </head>
<body onload="init();">
<script type="text/javascript">
<!--
var aCountry = new Array();
var aCity = new Array();
function init()
{
initCountryArray();
initCityArray();
fillCountryList('From');
fillCountryList('To');
fillCityList('From');
fillCityList('To');
}
function initCountryArray()
{
// Kolonne 1 = landeId
// Kolonne 2 = landeNavn
aCountry[0] = new Array("1", "Danmark");
aCountry[1] = new Array("2", "Sverige");
aCountry[2] = new Array("3", "Tyskland");
aCountry[3] = new Array("4", "Frankrig");
}
function initCityArray()
{
// Kolonne 1 = byId
// Kolonne 2 = landeId
// Kolonne 3 = byNavn
aCity[0] = new Array("1", "1", "København");
aCity[1] = new Array("2", "1", "Billund");
aCity[2] = new Array("3", "2", "Arlanda");
aCity[3] = new Array("4", "2", "Gardamoen");
aCity[4] = new Array("5", "3", "Hamborg");
aCity[5] = new Array("6", "3", "Flensborg");
aCity[6] = new Array("7", "4", "Nice");
aCity[7] = new Array("8", "4", "Cannes");
}
function showCity(s)
{
var oCity = eval(oCity = document.getElementById("City" + s));
var cityIndex = oCity[oCity.selectedIndex].value;
var cityId = aCity[cityIndex][0];
var cityName = aCity[cityIndex][2];
alert(cityId + ' : ' + cityName);
}
function fillCountryList(s)
{
var oCountry = eval(oCountry = document.getElementById("Country" + s))
for (var i=0 ; i<aCountry.length; i++)
oCountry.options[i] = new Option(aCountry[i][1], aCountry[i][0]);
}
function fillCityList(s)
{
var oCountry = eval(oCountry = document.getElementById("Country" +s))
var oCity = eval(oCity = document.getElementById("City" + s))
var selectedCountryValue = oCountry[oCountry.selectedIndex].value;
var index = 0;
oCity.length = 0;
for (var i=0; i<aCity.length; i++)
{
if (aCity[i][1] == selectedCountryValue)
{
oCity.options[index] = new Option(aCity[i][2], i);
index ++;
}
}
}
//-->
</script>
<form id="Form1" method="post" runat="server">
Fra land: <select id="CountryFrom" onchange="java script:fillCityList('From');"></select> Fra by: <select id="CityFrom"></select>
<br>
<br>
Til land: <select id="CountryTo" onchange="java script:fillCityList('To');"></select> Til by: <select id="CityTo"></select>
<br>
<br>
<input type="button" value="Vis fra land" onclick="java script:showCity('From');"> <input type="button" value="Vis til land" onclick="java script:showCity('To');">
</form>
</body>
</html>