Hello, I am trying this one instead I gave up on the other. This should work with only slight modification because I got most of it from a working script. Can someone please tell me where my error is? The image will not appear, I have a path to a real image. If you're wondering why I have the content inside a bracket is because I will be adding more to it later. This goes in the body. <BODY onload="changeImg();"> <img id="img" border="0"/> This goes in the external, or it can be tested on the same page. var content = new Array(); content[0] = ["http://www.website.com/3.jpg"]; content[1] = ["http://www.website.com/6.jpg"]; var counter = 0; function changeImg() { document.getElementById("img").src = content[counter-1][0]; counter++; if (counter == content.length) counter = 0; } setInterval("changeImg()", 40000);
It starts with counter being set to -1, which does not exist in the array. This should do it. <script type="text/javascript"> var content = new Array(); var counter = 0; content[0] = "http://www.website.com/3.jpg"; content[1] = "http://www.website.com/6.jpg"; function changeImg() { document.getElementById("img").src = content[counter]; counter++; if (counter == content.length) counter = 0; } setInterval("changeImg()", 40000); </script> Code (markup):
Thats preety nice code my friend, but if all the images have the same prefix then sum it up (http://www.website.com/)
Yeah, DRY (Don't repeat yourself). I just edited quick the original script. And the URLs are more of examples anyway.