PDA

View Full Version : toString()?


chrismiceli
11-22-2002, 02:43 AM
is there an opposite of toString() to covert a quoted variable to a variable w/o the quote?

glenngv
11-22-2002, 02:53 AM
use eval()

var myvar = 0;
var testvar = eval("myvar");
alert(testvar);

what exactly you want to do?
there could be better ways other than eval()

chrismiceli
11-22-2002, 02:59 AM
i have a variable name we0 and we1 and i need to access them through a for loop like this
for (i=0; i >= variable; ++i) {
we + i //i know that won't work but you get the point
//more code
}
i will try eval for my purposes. thanx for your help.

glenngv
11-22-2002, 03:14 AM
you can also use

window["we"+i];

or an array

chrismiceli
11-22-2002, 03:23 AM
my variable we0 and we1 are in another frame, when i try
test = window["parent.stats.we" + i];
alert(test);
i get undefined, we0 in the other page has a value of 1. still needs more debugging.

glenngv
11-22-2002, 03:31 AM
try:

//top to bottom accessing of frames
test = top.frames["stats"]["we" + i];
//or
//test = top.frames.stats["we" + i];
alert(test);

or

//bottom to top accessing of frames
test = parent.frames["stats"]["we" + i];
//or
//test = parent.frames.stats["we" + i];
alert(test);

chrismiceli
11-22-2002, 03:41 AM
i keep getting this alert in mozilla [Object object] for the alert(test) here is my syntax

var arr = parent.stats["we" + i];
alert(arr);

i tried the others variations, same alert.
here is the code on the framed page called "stats"

function val(value) {
this.value = value;
}
we0 = new val("1");
we1 = new val("2");

glenngv
11-22-2002, 03:47 AM
yes, that's because we0 and we01 are instances of the constructor val, so they are indeed objects. you need to access its properties like this:

var arr = parent.stats["we" + i];
alert(arr.value);

chrismiceli
11-22-2002, 04:30 AM
holy cow, you are 'da man glen, thanx :thumbsup: