|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Greetings,
Ok...I am trying to build an array using an objects id as a key and a defined element for it's value. Shouldn't the array have length? Am I not created the array correctly? Code Follows: <html> <script language="javascript"> document.menu = new Object(); document.menu.dropdown = new Array(); function createMenu() { var i; if (document.all) { for(i = 0; i < document.all('container').all.length; i++) { if ((document.all('container').all[i].level == 'menu') | | (document.all('container').all[i].level == 'submenu') | | (document.all('container').all[i].level == 'links')) { // Feed DropDown Array var curID = document.all('container').all[i].id; document.menu.dropdown[curID] = document.all('container').all[i]; } } // Check For Length alert(document.menu.dropdown.length); } } </script> <body onLoad="javascript: createMenu()"> <div id="container"> <div id="Main" level="menu" style="display: block; margin-left: 0px;"> <a href="#http://main" class="menu">Main</a><br /> </div> <div id="Secondary" level="submenu" style="display: block; margin-left: 10px;"> <a href="#http://sec" class="submenu">Secondary</a><br /> </div> <div id="Link" level="links" style="display: block; margin-left: 20px;"> <a href="#http://link" class="links">Links</a><br /> </div> </div> </body> </html> End Code Thanks for any help. Brian D. |
|
#2
|
|||
|
|||
|
associative arrays don't have lengths... use for in.
|
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Build An Array |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|