rawb Posted June 23, 2006 Share Posted June 23, 2006 Hello! I have a script written to change the information in a div every few seconds (via innerhtml), but for some reason it keeps giving me a "Stack overflow at line: 33" error. I really don't know what this means and could use some help.. if anyone could tell me what is wrong here I would appreciate it a lot. It's probably something really dumb and simple but I just need a fresh pair of eyes to look it over. Thanks in advance!Oh.. the onClick buttons work like a charm, so there's nothing wrong with the 'tick' function.. I think...[code]<script>//create two parallel arraysimagearray = new Array(3);textarray = new Array(3);imagearray[0] = "corporate.gif";imagearray[1] = "hosting.gif";imagearray[2] = "community.gif";textarray[0] = "corp";textarray[1] = "host";textarray[2] = "commute?";function tick(newimage, newtext, div) {//takes three string arguments, div being a reference to the div to be changedvar replacement = "image: " + newimage + "<br>text: " + newtext + "<br>";document.getElementById(div).innerHTML = replacement;}function changediv(imagearray, textarray, i) {//takes two array arguments and one number (the number in the parallel arrays on which to begin)//change the image!tick(imagearray[i], textarray[i], 'change');//calculate the next number in the array, or start over...i++;if (i >= imagearray.length) { i = 0;}// call this function again with a new number after so many seconds...setTimeout(changediv(imagearray, textarray, i), 2000);}</SCRIPT><body onLoad="changediv(imagearray, textarray, 2);"><a href=# onclick="tick(imagearray[1], textarray[1], 'change'); return false;">test</a><a href=# onclick="tick(imagearray[2], textarray[2], 'change'); return false;">test2</a><div id="change">image: none<br>text: none<br></div>[/code]By the way, these are lines 32 and 33 (it says the 'stack overflow' error is on 33).[code]//change the image!tick(imagearray[i], textarray[i], 'change');[/code] Quote Link to comment Share on other sites More sharing options...
nogray Posted June 23, 2006 Share Posted June 23, 2006 The error happens because you are calling the script in the setTimeout instead of using a string type.All you need is to change your setTimeout like this[code]setTimeout("changediv(imagearray, textarray, "+i+")", 2000);[/code] Quote Link to comment Share on other sites More sharing options...
rawb Posted June 24, 2006 Author Share Posted June 24, 2006 [!--quoteo(post=387318:date=Jun 23 2006, 06:56 PM:name=nogray)--][div class=\'quotetop\']QUOTE(nogray @ Jun 23 2006, 06:56 PM) [snapback]387318[/snapback][/div][div class=\'quotemain\'][!--quotec--]The error happens because you are calling the script in the setTimeout instead of using a string type.All you need is to change your setTimeout like this[code]setTimeout("changediv(imagearray, textarray, "+i+")", 2000);[/code][/quote]Works like a charm. Thanks a million man, I really appreciate it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.