Click to See Complete Forum and Search --> : Recursive function causing some difficulties


justin001
10-08-2003, 04:40 AM
I am using a recursive function to create a whole lot of DIVs which will be used as javascript popup menus. If there are submenus, different DIVS should be craeted, but it is just repeating menu elements that have already been created. The function is "createMenus"

Any help would be greatly appreciated!

IN THE BODY:

<script>createMenus(menu2Array);document.write(HTMLMenuContent.join("<br>"));</script>


THE SCRIPT

var menu2Array=
[
{name:"One",child:[{name:"Two",child:0},{name:"Three",child:[{name:"Four",child:[{name:"Six",child:0}]}]}]},
{name:"Seven",child:0},
{name:"Eight",child:0}
]

var HTMLMenuContent=new Array();

function createMenus(pArray)
{
var content="";
for (var i=0;i<pArray.length;i++)
{
content+="<div class='menuContainer' id='menu"+menuElAr["menus"].length+"'>";
menuElAr["menus"][menuElAr["menus"].length]="menu"+menuElAr["menus"].length;
if (pArray[i].child) createMenus(pArray[i].child);
content+=pArray[i].name+"<br>";
content+="</div>\n";
HTMLMenuContent[HTMLMenuContent.length]=content;
}
}

justin001
10-08-2003, 04:52 AM
Sorry, my mistake. Got it sorted!