Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:18
Using an array to add an element
Poster: cubefree
Dated: Wednesday July 21 2004 - 22:33:37 BST
I'm trying to use an array to generate a series:
Code:
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;");
}
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:
aI("text="+attnEG[0]+";showmenu=blank;");
if (attnEG[1]) aI("text="+attnEG[1]+";showmenu=blank;");
if (attnEG[2]) aI("text="+attnEG[2]+";showmenu=blank;");
if (attnEG[1]) aI("text="+attnEG[1]+";showmenu=blank;");
if (attnEG[2]) aI("text="+attnEG[2]+";showmenu=blank;");
Poster: kevin3442
Dated: Thursday July 22 2004 - 0:01:39 BST
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:
for (i=0;i++;i<attnEG.length) {
should be this:
Code:
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