martynball
07-24-2010, 10:28 PM
How can I use a string to select a variable?
E.g.
function load_menu(menu) {
//Availible menus
var login = Array('Login','Register','Recovery');
var settings = Array('Profile','Account','something');
//Menu container ID's
var cons = Array('menuitem1','menuitem2','menuitem3');
for ( var i = 0; i < cons.length; i++ ) {
document.getElementById(cons[i]).innerHTML = menu[i];
alert(menu[i]);
}
}
"menu" is "login".
menu[i] should reference the "login" variable and then put one of the values for the login variable array in its place.
If you understand what I mean?
So if menu is settings then the settings array would be used.
E.g.
function load_menu(menu) {
//Availible menus
var login = Array('Login','Register','Recovery');
var settings = Array('Profile','Account','something');
//Menu container ID's
var cons = Array('menuitem1','menuitem2','menuitem3');
for ( var i = 0; i < cons.length; i++ ) {
document.getElementById(cons[i]).innerHTML = menu[i];
alert(menu[i]);
}
}
"menu" is "login".
menu[i] should reference the "login" variable and then put one of the values for the login variable array in its place.
If you understand what I mean?
So if menu is settings then the settings array would be used.