scooby545
11-20-2008, 11:48 AM
Basically i am trying to get this script to cycle through the images in the array in a loop with a timed delay :confused:
The script cycles the images through fine but will not reset back to the first image :( I just cant figure out whats going wrong and its driving me mad :mad:
Please help!! :confused:
<html>
<head>
<title>Testing Page</title>
<script type="text/javascript">
var myCounter = 0;
var myArray = ['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg'];
var arraylen = myArray.length;
function changepic()
{
document.getElementById('test').innerHTML = 'Counter : ' +myCounter + '<br>Array : ' +arraylen + '<br><img src="' +myArray[myCounter] + '">';
myCounter++;
}
function changepic2()
{
var myCounter = 0;
document.getElementById('test').innerHTML = 'Counter : ' +myCounter + '<br>Array : ' +arraylen + '<br><img src="' +myArray[myCounter] + '">';
}
function alertme()
{
if(arraylen > myCounter){
intervalID = setInterval(changepic, 5000);
}else{
intervalID = setInterval(changepic2, 5000);
}
}
</script>
</head>
<body bgcolor='#ffffff' onload="alertme();">
<div id='test'>
<img src="image1.jpg">
</div>
</body>
</html>
The script cycles the images through fine but will not reset back to the first image :( I just cant figure out whats going wrong and its driving me mad :mad:
Please help!! :confused:
<html>
<head>
<title>Testing Page</title>
<script type="text/javascript">
var myCounter = 0;
var myArray = ['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg'];
var arraylen = myArray.length;
function changepic()
{
document.getElementById('test').innerHTML = 'Counter : ' +myCounter + '<br>Array : ' +arraylen + '<br><img src="' +myArray[myCounter] + '">';
myCounter++;
}
function changepic2()
{
var myCounter = 0;
document.getElementById('test').innerHTML = 'Counter : ' +myCounter + '<br>Array : ' +arraylen + '<br><img src="' +myArray[myCounter] + '">';
}
function alertme()
{
if(arraylen > myCounter){
intervalID = setInterval(changepic, 5000);
}else{
intervalID = setInterval(changepic2, 5000);
}
}
</script>
</head>
<body bgcolor='#ffffff' onload="alertme();">
<div id='test'>
<img src="image1.jpg">
</div>
</body>
</html>