I'm trying, but unsuccessfully, to get the value of a variable, where the variable name is dynamic
var v_1playerName = document.getElementById("id_1playerName").value;
var v_2playerName = document.getElementById("id_2playerName").value;
for (i = 1; i <=5 i++) {
alert(window["v_"+i+"playerName"]);
}
Is this possible?
v_1playerNameand not the value of the variable.var windowName = "v_"+i+"playerName"; alert(window[windowName]);?eval, but that's evil (even if you do not have a security issue, it makes your code slower); but what you really should be doing is having either an object or array to hold both of your values.