Hi,
I am trying to create a simple hierarchical menu with data for menus stored in arrays. It looks like this with backgroundArray[8] linking to a submenu populated with values from child1Array. backgroundArray[8].child is a string at at some point in my createMenu() I need to convert the string "child1" back into an array. To do this I have used
var subMenuArray = eval(backgroundArray[8].child + "Array"
I copied this from a similar menu in a book and it worked fine in their example but it doesn't for me.
Is this an apprpriate use of eval?
Ideally I would like to store backgroundArray[8].child as an array and not a string but I'm doing something wrong there too. Should it be possible? How would I change the arrayValues() function?
all ideas welcome
thanks
ALS
function arrayValues(text,child,image,url,ID)
{
this.text = text;
this.child = child;
this.image = image;
this.url = url;
this.ID = ID; //menu ID
}
function menuSetUp()
{
backgroundArray = new Array();
backgroundArray[1] =new arrayValues("Background",null,"minisun","page1.htm","menu1"
;
backgroundArray[2] =new arrayValues("Sustainability",null,null,"backgroundSustainable.htm","menu1"
;
backgroundArray[3] =new arrayValues("Environment",null,null,"backgroundEnvironment.htm","menu1" );
backgroundArray[4] =new arrayValues("Pollution",null,null,"backgroundPollution.htm","menu1"
;
backgroundArray[5] =new arrayValues("Recycling",null,null,"backgroundRecycling.htm","menu1"
;
backgroundArray[6] =new arrayValues("Energy",null,null,"backgroundEnergy.htm","menu1"
;
backgroundArray[7] =new arrayValues("Water",null,null,"backgroundWater.htm","menu1"
;
backgroundArray[8] =new arrayValues("Biodiversity","child1",null,null,"menu1"
;
createMenu(backgroundArray)
child1Array = new Array();
child1Array[1] = new arrayValues("more biodiversity 1",null,null,"subBio1.htm","menu7"
;
child1Array[2] = new arrayValues("more biodiversity 2",null,null,"subBio2.htm","menu7"
;
child1Array[3] = new arrayValues("more biodiversity 3",null,null,"subBio3.htm","menu7"
;
child1Array[4] = new arrayValues("more biodiversity 4",null,null,"subBio4.htm","menu7"
;
child1Array[5] = new arrayValues("more biodiversity 5",null,null,"subBio5.htm","menu7"
;
child1Array[6] = new arrayValues("more biodiversity 6",null,null,"subBio6.htm","menu7"
;
child1Array[7] = new arrayValues("more biodiversity 7",null,null,"subBio7.htm","menu7"
;
I am trying to create a simple hierarchical menu with data for menus stored in arrays. It looks like this with backgroundArray[8] linking to a submenu populated with values from child1Array. backgroundArray[8].child is a string at at some point in my createMenu() I need to convert the string "child1" back into an array. To do this I have used
var subMenuArray = eval(backgroundArray[8].child + "Array"
I copied this from a similar menu in a book and it worked fine in their example but it doesn't for me.
Is this an apprpriate use of eval?
Ideally I would like to store backgroundArray[8].child as an array and not a string but I'm doing something wrong there too. Should it be possible? How would I change the arrayValues() function?
all ideas welcome
thanks
ALS
function arrayValues(text,child,image,url,ID)
{
this.text = text;
this.child = child;
this.image = image;
this.url = url;
this.ID = ID; //menu ID
}
function menuSetUp()
{
backgroundArray = new Array();
backgroundArray[1] =new arrayValues("Background",null,"minisun","page1.htm","menu1"
backgroundArray[2] =new arrayValues("Sustainability",null,null,"backgroundSustainable.htm","menu1"
backgroundArray[3] =new arrayValues("Environment",null,null,"backgroundEnvironment.htm","menu1" );
backgroundArray[4] =new arrayValues("Pollution",null,null,"backgroundPollution.htm","menu1"
backgroundArray[5] =new arrayValues("Recycling",null,null,"backgroundRecycling.htm","menu1"
backgroundArray[6] =new arrayValues("Energy",null,null,"backgroundEnergy.htm","menu1"
backgroundArray[7] =new arrayValues("Water",null,null,"backgroundWater.htm","menu1"
backgroundArray[8] =new arrayValues("Biodiversity","child1",null,null,"menu1"
createMenu(backgroundArray)
child1Array = new Array();
child1Array[1] = new arrayValues("more biodiversity 1",null,null,"subBio1.htm","menu7"
child1Array[2] = new arrayValues("more biodiversity 2",null,null,"subBio2.htm","menu7"
child1Array[3] = new arrayValues("more biodiversity 3",null,null,"subBio3.htm","menu7"
child1Array[4] = new arrayValues("more biodiversity 4",null,null,"subBio4.htm","menu7"
child1Array[5] = new arrayValues("more biodiversity 5",null,null,"subBio5.htm","menu7"
child1Array[6] = new arrayValues("more biodiversity 6",null,null,"subBio6.htm","menu7"
child1Array[7] = new arrayValues("more biodiversity 7",null,null,"subBio7.htm","menu7"