Click to See Complete Forum and Search --> : cycling images


scoe
10-19-2003, 10:38 PM
hi there
i've got a code that is meant to cycle some images every 2 seconds.

however the code doesn;t work. the error i get is that the array is not defined and currentad is not defined.

here is my code:
<html>
<head>

<script type="text/javascript">
#theimages=new array("aminorforest.jpg", "flypanam.jpg", "mogwai.jpg");#
currentad=0;
numad=3;
function cycle() {
if (document.images) {
#currentad++;#
if (currentad==numad) {
currentad=0;
}
document.adimage.src=theimages[currentad];
setttimeout("cycle()", 2000);
}
}
</script>


<title></title>

</head>

<body onload="cycle()">
<img src="aminorforest.jpg" name="adimage">
</body>

</html>

the lines between the hashes are the lines with the error.

does anyone know how to get fix these errors??

thanks

fredmv
10-19-2003, 10:45 PM
Try this:<script type="text/javascript">
theimages=new array("aminorforest.jpg", "flypanam.jpg", "mogwai.jpg");
currentad=0;
numad=3;
function cycle() {
if (document.images) {
currentad++;
if (currentad==numad) {
currentad=0;
}
document.adimage.src=theimages[currentad];
setttimeout("cycle()", 2000);
}
}
</script>I removed the hash marks from it. Those shouldn't be there. ;)

scoe
10-19-2003, 10:49 PM
i've tried it but it still doesn't work

the images don't cycle and i still get the same error.

something along the lines that the array isn't defined and the currentad is defined.

fredmv
10-19-2003, 11:05 PM
This will work:<script type="text/javascript">
theimages=new Array("aminorforest.jpg", "flypanam.jpg", "mogwai.jpg");
currentad=0;
numad=3;
function cycle() {
if (document.images) {
currentad++;
if (currentad==numad) {
currentad=0;
}
document.adimage.src=theimages[currentad];
setTimeout("cycle()", 2000);
}
}
</script>Remember that JavaScript is case sensitive. ;)

scoe
10-19-2003, 11:08 PM
forgot about that

thanks for the help mate

fredmv
10-19-2003, 11:10 PM
You're welcome. :D