- Dec 1, 2000
- 2,419
- 0
- 0
Below is an excerpt from what I am working on.
It is a fancy-smansy drop-down (actually drop-sideways) menu system.
I know CSS like I know the back of my own hand, but Javascript Objects is fresh and new. (Actually, I don't know the back of my own hand very well, but I know it like I know... my girlfriend. Wait, I don't have a girlfriend. Forget it.)
Anyway, you'll notice that I want to call addMenuItem numerous times. So, for example, when you mouse over corporate, you'll see Awards and Innovations and Board and Administration in the next level of menu.
I have the mechanics of displaying this all worked out elsewhere in my script.
So here's my problem. Obviously each time I call addMenuItem, it erases the previous item in that menu group.
Anyone who has any computer science background at this point thinks "DING! It's time for an array!"
At first I tried making an array inside MenuGroup. var myArray = new Array(). I had low hopes of this working because it is clearly a local array, and I can't mess with it from addMenuItem()
Next I tried making strItemName and strItemURL into arrays. Let's jsut say this.strItemName[this.iMenuItems] = strItemName produces some really interesting errors.
So: how the heck do I do this?!
	
	
	
		
			
			It is a fancy-smansy drop-down (actually drop-sideways) menu system.
I know CSS like I know the back of my own hand, but Javascript Objects is fresh and new. (Actually, I don't know the back of my own hand very well, but I know it like I know... my girlfriend. Wait, I don't have a girlfriend. Forget it.)
Anyway, you'll notice that I want to call addMenuItem numerous times. So, for example, when you mouse over corporate, you'll see Awards and Innovations and Board and Administration in the next level of menu.
I have the mechanics of displaying this all worked out elsewhere in my script.
So here's my problem. Obviously each time I call addMenuItem, it erases the previous item in that menu group.
Anyone who has any computer science background at this point thinks "DING! It's time for an array!"
At first I tried making an array inside MenuGroup. var myArray = new Array(). I had low hopes of this working because it is clearly a local array, and I can't mess with it from addMenuItem()
Next I tried making strItemName and strItemURL into arrays. Let's jsut say this.strItemName[this.iMenuItems] = strItemName produces some really interesting errors.
So: how the heck do I do this?!
		Code:
	
	function MenuGroup(strGroupName, strGroupURL) {
	// Properties
	this.iMenuItems		= 0;
	this.strGroupName 	= strGroupName;
	this.strGroupURL	= strGroupURL;
	// Methods
	this.addMenuItem        = addMenuItem;
}
function addMenuItem(strItemName, strItemURL) {
	this.strItemName	= strItemName;
	this.strItemURL	        = strItemURL;
	this.iMenuItems	        = this.iMenuItems + 1;
}
var x = new MenuGroup("Corporate", "default.asp");
x.addMenuItem("Awards and Innovations", "awards.asp");
x.addMenuItem("Board and Administration", "board.asp"); 
				
		 
			 
 
		 
 
		 
 
		 
 
		
 Facebook
Facebook Twitter
Twitter