Forum Moderators: open
arr = new Array(
["http://www.google.com/some.img"]
);
now = new Date()
nowDate = now.getMinutes()
function change(){
if(nowDate > arr.length) { return; }
document.getElementById("img").src = arr[nowDate-1][0];
setTimeout('change()',1000);
}
if condition is true, function change will exit without reseting timeout. Reorder statements like this maybe?
function change(){
setTimeout('change()',1000);
if(nowDate > arr.length) { return; }
document.getElementById("img").src = arr[nowDate-1][0];
}
Not sure what code is intended to as there is only one image in array and nowDate does not appear to change between timeouts?
Could I include another "if" statement? Something that says if element by id does this then setTimeout? Anyone have a good idea on how to do that? Thanks.
I'm not sure what you're trying to achieve, but your code would have to look something a bit more like this...
var arr = new Array(
["http://www.google.com/some.img"]
);
var now = new Date();
var img = document.getElementById("img");
function change(){
var nowDate = now.getMinutes()
if (nowDate > arr.length) { return; }
img.src = arr[nowDate-1][0];
setTimeout('change()',1000);
} However, I am certainly not saying this will will do anything useful.
Kaled.