Click to See Complete Forum and Search --> : calling variables from variables...


IxxI
04-24-2003, 07:03 AM
I'd better explain, I have a variable, i, which equals 0, and gets incremented everytime a function is run. I also have 3 more variables txt0, txt1 and txt2, which I want to use to change the InnerHTML of a div. To do this I have a further variable txtnum, which equals 'txt'+i+'' - therefore when i=0 txtnum=txt0. What I want to know is, is there anyway of using txtnum in InnerHTML to return whatever the value of txt0 is.
So if txt0="hello" I want something like

window.top.document.getElementById("mainbox").InnerHTML=txtnum

and therefore the text in mainbox is "hello".
I know the code above doesn't work, and I've also tried +txtnum+ and variants, and also InnerHTML.value. I just can't get it to work, anyone any ideas?

IxxI

AdamBrill
04-24-2003, 07:33 AM
I think this is what you want:

window.top.document.getElementById("mainbox").InnerHTML=eval("txt"+num);

Let me know if that isn't what you wanted... ;)

IxxI
04-24-2003, 07:43 AM
Thank you - perfect! :D

IxxI