Jump to content

Javascript Object Oriented Concepts


Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/203591-javascript-object-oriented-concepts/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.