Forum Moderators: open
I am using the following variables in a for loop to access variables based on the "i" value which starts at 1 and continues until the for loop meets a specified variable.
The issue below is that it literally produces the string value.
eg. salutation="x.salutation"+i+".value"
after execution salutation will contain x.salutation1.value (assuming i was 1 at this point)
What I would like to be assigned is the actual value retrieved by x.salutation1.value
Can someone please help me find a nice solution here?
var salutation = null;
eval("salutation=x.salutation"+i+".value");
Another way is (all browsers I think)...
var salutation = null;
eval("salutation=window.forms['x'].salutation"+i+".value");
Best way (imo) is to set an id="salutation1", &c, on your form entrys, then use...
salutation=document.getElementById("salutation"+i).value;
Jordan
The first method works fine and it also seems to work just the same in netscape.
However, the second method that sounds better since you think it works for all browsers doesn't work. It actually produced the same results as my initial code for some reason.
var salutation = null;
eval("salutation=window.forms['x'].salutation"+i+".value");
In the above code does the 'x' assume my form is called "x" or is it that it assumes the reference 'x' refers to a live form? I have tried 'x' and also the actual form name 'reg2' just to make sure I wasn't making a mistake.
I haven't tested the third 1 because my radio buttons haven't been coded with ids.
But to answer your question, the window.forms collection allows for indexing by the form name, which I was assuming to be 'x' -- I didn't realize that 'x' was a reference to the form and not the form name. My bad.
Jordan