Click to See Complete Forum and Search --> : populating an array
jazzyjade
06-12-2003, 05:12 PM
In the code below, I want to create an array and fill it with variables. parent.hidden.cs1_response[i] represents the variables and they are stored in a hidden frame. I know the variables are there because if I set an alert message in the function, I have no problem returning the values. But when this function runs, I get an error message that says "parent.hidden.cs1_response is null or not an object." There are 203 variables: parent.hidden.cs1_response1 to parent.hidden.cs1_response203. I had it all hard coded but that was awfully long and I thought this would work. Any ideas?
var userResponsesCS1 = new Array(203);
function assignResponses1(){
for(var i=0; i<204; i++) {
userResponsesCS1[i] = parent.hidden.cs1_response[i];
} }
Charles
06-12-2003, 05:18 PM
Originally posted by jazzyjade
Any ideas? Several. If you could post the URL then we could see which one, if any, applies.
jazzyjade
06-13-2003, 09:55 AM
charles~ i'd love to be able to send a link but i'm on an intranet. and, unfortunately, the code is way too long to post here.
dave~ thanks for the suggestion! right now, on all my pages, i send variables to parent.hidden. i just send them as regular variables like this: response1 = parent.hidden.cs1_response0. those are the variables that i'm trying to put into an array right. but it never occured to me that i could create an array just fill it as i go along instead of just sending variables and building the array later.
but i'm not sure how to write the code, that initialized the array, to the frame parent.hidden.
currently, the variables are sent when a user clicks a button and a function is run. in the code below, i changed the function so that it adds the user's response to the array(blue lines). but i need to initialize the array in the first if statement (submitClicked ==1). var userRespCS1 = newArray(204); is what i want to send to parent.hidden to initialize the array. but i'm not sure how i would write it. parent.hidden.var userRespCS = newArray(204); doen't work.
if (submitClicked == 1) {
orderSelected[0] = text; //text refers to the the response the user entered
eval("var userRespCS1 = new Array(204);
eval("parent.hidden.userRespCS1["+num+"] = orderSelected[0]");} // num is a variable increases each time the user enters the function that calls this function
else if (submitClicked == 2) {
orderSelected[1] = text;
eval("parent.hidden.userRespCS1["+num+"] = orderSelected[1]");}
else if (submitClicked == 3) {
orderSelected[2] = text;
eval("parent.hidden.userRespCS1["+num+"] = orderSelected[2]");}
else if (submitClicked == 4) {
orderSelected[3] = text;
eval("parent.hidden.userRespCS1["+num+"] = orderSelected[3]");}
else if (submitClicked == 5) {
orderSelected[4] = text;
eval("parent.hidden.userRespCS1["+num+"] = orderSelected[4]");}
else if (submitClicked == 6) {
orderSelected[5] = text;
eval("parent.hidden.userRespCS1["+num+"] = orderSelected[5]");}
}
SlankenOgen
06-14-2003, 10:08 AM
This line-
eval("var userRespCS1 = new Array(204);
is missing a closing bracket.
~mgb