Hi everyone,
Could someone help me out on this one? The story is, I have got a fixed html code which I can not change. There is a div contaning a picture, I need to change that picture to show five other pictures randomly using getElementById.
I have got some js coding already, but couldnt manage to change that div. My ideas were like creating a new function {window.onLoad getElementById then document.write and the rest od the code for the random pics, but it wasnt working. Tried to create a new var for the Math.floor(Math.random... and then combine this together in different ways.. Nothing. I am new to JS(only 2months) anyone could help me out on this one?
Thanks
Here is the JS code I have ps that commented document.write line is working but instead of displaying it on the top, it should be in a specific div.
var delay=1000; //set delay in miliseconds
var curindex=0;
var randomimages=new Array();
randomimages[0]="images/img06.jpg";
randomimages[1]="images/img07.jpg";
randomimages[2]="images/img08.jpg";
randomimages[3]="images/img09.jpg";
randomimages[4]="images/img10.jpg";
var preload=new Array();
for (n=0;n<randomimages.length;n++)
{
preload[n]=new Image();
preload[n].src=randomimages[n];
}
function changediv ()
{
document.getElementById('splash').innerHTML=document.write('<img name="splash" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'">');
}
// window.onload=changediv();
// window.onload=getElementById('splash'){document.write(randomimages[Math.floor(Math.random()*(randomimages.length)))};
// document.write('<img name="splash" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'">');
function rotateimage()
{
if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){
curindex=curindex==0? 1 : curindex-1;
}
else
curindex=tempindex;
document.images.splash.src=randomimages[curindex];
}
setInterval("rotateimage()",delay);