Menu Automation Script & Concatenating Variables

admin

Administrator
Staff member
Hello,

I'm trying to create a basic menu navigation system. What I want it to do is to read in a list of variables (actually, sets of two variables - the words of the link and the actual href of the link) and then spit out some HTML. However, I don't want the user to have to explicitly state how many sets of variables there are; I just want them to be able to define as many of them as they want in a separate file and never touch the script. I guess this would be counting variables. I'm confused on how to actually get the loop to work to use the variable name instead of a string, though. Here's the basic start of it:

//this part would be in some other file
item_1 = "Menu Item 1";
item_url_1 = "/test1.html"
item_2 = "Menu Item 2";
item_url_2 = "/test1.html"
item_3 = "Menu Item 1";
item_url_3 = "/test1.html"

/*this would be in the main script file, and handle the output of the script. I haven't written the rest of it yet :) */
count = 1;

function writeout(){
while(item_+count)
{
document.write(item_+count);
count++;
}
}

The problem is that it won't concatenate the variable name with the count. Is it possible to do this, or should I find a different approach to counting a number of variables?

Thanks!
RoNb
 
Back
Top