Jump to content


This topic is now archived and is closed to further replies.


JS arrays and variables

Recommended Posts


How would i make something like this work


    function showMore(num){
        theText[0] = "this is 0";
        theText[1] = "this is 1";
        theText[2] = "this is 2";
        theText[3] = "this is 3";
        theText[4] = "this is 4";
        theText[5] = "this is 5";

<a href="#" onclick="showMore('0'); return false;">0</a><br>
<a href="#" onclick="showMore('1'); return false;">1</a><br>
<a href="#" onclick="showMore('2'); return false;">2</a><br>
<a href="#" onclick="showMore('3'); return false;">3</a><br>
<a href="#" onclick="showMore('4'); return false;">4</a><br>
<a href="#" onclick="showMore('5'); return false;">5</a><br>[/code]

I keep getting "theText not defined" error message.


Oops, this always happens. As soon as i ask the question, i figure out the answer

i forgot to define the array

[code]theText = new Array();[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.