programming.name Posted June 2, 2010 Share Posted June 2, 2010 Hi, Please consider the following chunk of code: <FORM NAME="nav"> <SELECT NAME="SelectURL" onChange= "document.location.href= document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value"> <OPTION VALUE="" SELECTED>Please select a link: <OPTION VALUE="http://www.example.com"> Go to somewhere </SELECT> </FORM> From the code above, we have something like: document.location.href= document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value. Could you please explain about the code after the "document.location.href=" elemnet by element? I can baerly understand why this code could link to somewhere. Thanks. Quote Link to comment Share on other sites More sharing options...
dabaR Posted June 2, 2010 Share Posted June 2, 2010 document.location.href= document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value Let's do it backwards: .value = the value of options[document.nav.SelectURL.selectedIndex] = the selected option of (this is basically a lookup into an array, array[index]) document.nav.SelectURL = the SelectURL select box, that is inside the nav form, that is inside the document(the whole HTML document) So all in one sentence: The value of the selected option of the SelectURL select box, that is inside the nav form, that is inside the document = document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value Hope that helps! -- Dan Bernardic http://dan.bernardic.ca Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.