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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.