Create the init() function. Within this function do the following:
a) Create a variable named allSelect that references all of the selection elements in
the document.
b) For each item within the allSelect object collection, add an onchange event
handler that runs the loadLink() function when the selection list changes.
Create the loadLink() function. The purpose of this function is to cause the browser
to load a URL from a selection list. Add the following commands to the function:
a) Create a variable named sIndex that points to the index of the selected option in
the current selection list. (Hint: Use the this keyword to reference the current
selection list.)
b) Web pages can be loaded using the commandlocation.href = url;
where url is the URL of theWeb page. Enter this command into the function using the
value of the selected option from the selection list as the value of url. (Hint: Use the
sIndex variable to point to the selected option from the current selection list.)
MY CODE:
window.onload = init;
var allSelect;
var sIndex;
function init() {
allSelect = document.getElementsByTagName("select");
for (var i = 0; i < allselect.length; i++) {
if (allselect[i].className == "optionLinks") allSelect.push(allSelect[i]);
allSelect[i].onchange = loadLink;
}
}
function loadLink(siteList) {
var sIndex = this.id + "optionLinks";
location.href = siteList.options[sIndex].value;
}