Hi,
Can someone tell me how to access javascript variable dynamically?? For instance instead of:
status[0] = k0;
status[1] = k1;
status[2] = k2;
I want to do something like:
for(i=0; i<2; i++) {
status[0] = k + i;
}
where javascript substitutes the i with the current value of i, then evaluates the whole thing as a variable.
Thanks
Javascript dynamic variable access
Started by haleh, Mar 15 2006 07:00 PM
1 reply to this topic
#1
Posted 15 March 2006 - 07:00 PM
#2
Posted 15 March 2006 - 07:31 PM
Ok nevermind I found the eval function. Here is what I did:
function validate_form() {
var isvalid = new Array();
for(i=0; i<23; i++) {
isvalid[i] = false;
}
//check all the questions that have radio buttons
for(i=0; i<23; i++) {
j=i+1;
status = getSelectedRadio( eval("document.survey.q"+j) ); //EVAL
isvalid[i] = status;
}
for(i=0; i<23; i++) {
if(!isvalid[i]) {
valid = false;
alert("Please answer question " + (i+1));
return false;
}
}
}
function validate_form() {
var isvalid = new Array();
for(i=0; i<23; i++) {
isvalid[i] = false;
}
//check all the questions that have radio buttons
for(i=0; i<23; i++) {
j=i+1;
status = getSelectedRadio( eval("document.survey.q"+j) ); //EVAL
isvalid[i] = status;
}
for(i=0; i<23; i++) {
if(!isvalid[i]) {
valid = false;
alert("Please answer question " + (i+1));
return false;
}
}
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
