Click to See Complete Forum and Search --> : Incrementing text for display


gns100
11-04-2003, 01:39 PM
In a JS function I have


Text_1 = "ONE"
Text_2 = "TWO"
Text_3 = "THREE"

Using something like the following I want to display the text.

for(i=1; i<4; i++) {

text_id = "Text_" + i;

}

What I get is the strings in text_id ..... Text_1, Text_2, Text_3.

What I want is ONE, TWO, THREE.

I reality I have i = 100, so I need to do it this way.

Thanks for any help.

requestcode
11-04-2003, 01:58 PM
Try chaning this line:
text_id = "Text_" + i;

To this:
text_id += eval("Text_" + i);

Charles
11-04-2003, 02:22 PM
<script type="text/javascript">
<!--
Text_1 = 'ONE';
Text_2 = 'TWO';
Text_3 = 'THREE';
document.write('<ul>');
for (i=1; i<=3; i++) {document.write('<li>', window['Text_' + i], '</li>')};
document.write('</ul>');
// -->
</script>

gns100
11-04-2003, 02:37 PM
Thanks, guys, I got it to work.