Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help with some script

DregusDregus Member Posts: 1
I am new to javascript and am currently taking a course in which I am being asked to use an external .js file and include the following items within.

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 command
location.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.)

So far I have put this together but I believe I am way off track.

//window.onload = init;

function init() {
var allSelect = optionLinks;
onchange="loadLink";
}

function loadLink() {
var sindex = siteList.options[siteList.selectedIndex].value;
window.location = sindex;
}//

any help out be awesome. I guess I am not grasping the concepts fully because it seems to me this code should be relatively easy.
Sign In or Register to comment.