Using an array to add an element

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
User avatar
cubefree
Super Advanced
Super Advanced
Posts: 82
Joined: Fri Aug 01, 2003 3:16 am
Location: Seattle, WA
Contact:

Using an array to add an element

Post by cubefree »

I'm trying to use an array to generate a series:

Code: Select all

var attnEG = new Array();
attnEG[0] = "Text ONE";
attnEG[1] = "Text TWO";

// then .... later ...

for (i=0;i++;i<attnEG.length) {
	aI("text="+attnEG[i]+";showmenu=blank;");
}
But I don't get two separate elements. I get "Text ONEText TWO" positioned together on the same line, nor does the subimage appear at all.

Anyone ever tried to build menus this way before?

Another possibility is also... which does work.

Code: Select all

aI("text="+attnEG[0]+";showmenu=blank;");
if (attnEG[1]) aI("text="+attnEG[1]+";showmenu=blank;");
if (attnEG[2]) aI("text="+attnEG[2]+";showmenu=blank;");
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi cubefree,

If the for statement posted in your example is how you're actually doing it, then it may just be a slight syntax error. In your example, you have the increment expression before the condition, but it should be the reverse: condition before increment. In other words this:

Code: Select all

for (i=0;i++;i<attnEG.length) { 
should be this:

Code: Select all

for (i=0;i<attnEG.length;i++) { 
Other than that, it seems to me that the approach should work just fine.

Hope that helps,

Kevin
User avatar
cubefree
Super Advanced
Super Advanced
Posts: 82
Joined: Fri Aug 01, 2003 3:16 am
Location: Seattle, WA
Contact:

Post by cubefree »

I gotta stop giving you these easy ones! Thx
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

cubefree wrote:I gotta stop giving you these easy ones! Thx
<grin> The only reason I caught it was that I do the same thing myself. Don't tell anyone!

Cheers,

Kevin
Post Reply