I have browsed StackOverflow and found a couple questions/answers that are close but not exact for my situation. I am following this example:
http://www.javascriptkit.com/javatutors/selectcontent2.shtml
And my JavaScript code is like this:
var cityList = document.selectionForm.cityListBox;
var cities = new Array();
cities[0] = "";
cities[1] = ["Eugene|eugeneValue", "Portland|portlandValue", "Salem|salemValue"];
cities[2] = ["Bellingham|bellinghamValue", "Onalaska|onalaskaValue", "Seattle| seattleValue"];
function updateCities(cityGroup)
{
cityList.options.length = 0;
if (cityGroup > 0)
{
for (i = 0; i < cities[cityGroup].length; i++)
{
cityList.options[cityList.options.length] = new Option(cities[cityGroup][i].split("|")[0], cities[cityGroup][i].split("|")[1]);
}
}
}
And my HTML code like this:
<form name="selectionForm">
<select name="stateListBox" size="3" style="width: 150px" onchange="updateCities(this.selectedIndex);">
<option selected>Select a State >></option>
<option value="oregon">Oregon</option>
<option value="washington">Washington</option>
</select>
<select name="cityListBox" size="3" style="width: 150px" onclick="alert(this.options[this.options.selectedIndex].value);">
</select>
</form>
As far as I can tell, this should work as described by the link above. I have had great experiences with the JavaScript Kit website, but this time I think I am missing something.
When I actually publish this to the page, I can click the states but nothing appears in the city box, as is expected.
Can anyone see the problem here?
Any help is appreciated.
PS – I apologize if there is a double post that I missed. Any references are also greatly appreciated.
in the for loop in
updateCities, the statement starts withcitylist.optionschange
citylisttocityList(Capital L)Will work then.