Eccolo comunque:
codice:
<html>
<head>
<title>Dynamic Select Example</title>
<script type="text/javascript">
// Create arrays containing state cities
// Note: These arrays could be created dynamically
var arrStates, arrFlorida, arrNewYork, arrTennessee
arrFlorida = ["Daytona Beach", "Miami", "Orlando", "Tampa"]
arrNewYork = ["Albany","New York", "Oakland", "Rochester"]
arrTennessee = ["Gatlinburg", "Knoxville", "Memphis", "Nashville"]
arrStates =[arrFlorida, arrNewYork, arrTennessee]
// Function to handle dynamically altering the contents of the City List box
function handleChange(newDisplay)
{ var StateSelect, CitySelect, NumEntries, i
StateSelect = document.frm.States
CitySelect = document.frm.Cities
// Delete all entries in the cities list box
for (i = CitySelect.length; i > 0; i--)
{
CitySelect.options[i-1] = null
}
// Add comment option to City List box
CitySelect.options[0] = new Option("-- Select City --",0)
// If state is selected add its cities to the City List box
if (newDisplay >= 0)
{
NumEntries = arrStates[newDisplay].length
for (i = 1; i <= NumEntries; i++)
{
CitySelect.options[i] = new Option((arrStates[newDisplay])[i-1],(i))
}
}
CitySelect.selectedIndex = 0
}
</script>
</head>
<body>
<form name="frm" action="">
States:
<select name="States" onChange="handleChange(this[this.selectedIndex].value)">
<option value="-1">-- Select State --
<option value="0">Florida
<option value="1">New York
<option value="2">Tennessee
</select>
Cities:
<select name="Cities">
<option value="-1">-- Select City --
<option>
<option>
<option>
<option>
</select>
<script type="text/javascript">
handleChange(-1)
</script>
</form>
</body>
</html>