Javascript random images
Posted: Tue Aug 19, 2008 10:52 am
I have created javascript to get random images and display them to div elements on the html page.
I have the code working so far as generating random images ok.
the problem.....
i have 5 div elements....sometimes the same images is showing 2 or more times on different div areas and i want each one of the 5 div areas to display different images from the array.
I have the code working so far as generating random images ok.
the problem.....
i have 5 div elements....sometimes the same images is showing 2 or more times on different div areas and i want each one of the 5 div areas to display different images from the array.
any ideas?function ranImage() {
images = new Array();
images[0] = "<a href = '#'><img src='../images/topAds/0.jpg' alt='' border='0'></a>";
images[1] = "<a href = '#'><img src='../images/topAds/1.jpg' alt='' border='0'></a>";
images[2] = "<a href = '.#'><img src='../images/topAds/2.jpg' alt='' border='0'></a>";
images[3] = "<a href = '#'><img src='../images/topAds/3.jpg' alt='' border='0'></a>";
images[4] = "<a href = '#'><img src='../images/topAds/4.jpg' alt='' border='0'></a>";
images[5] = "<a href = '#'><img src='../images/topAds/5.jpg' alt='' border='0'></a>";
images[6] = "<a href = '#'><img src='../images/topAds/6.jpg' alt='' border='0'></a>";
images[7] = "<a href = '#'><img src='../images/topAds/7.jpg' alt='' border='0'></a>";
images[8] = "<a href = '#'><img src='../images/topAds/8.jpg' alt='' border='0'></a>";
images[9] = "<a href = '#'><img src='../images/topAds/9.jpg' alt='' border='0'></a>";
images[10] = "<a href = '#'><img src='../images/topAds/10.jpg' alt='' border='0'></a>";
index1 = Math.floor(Math.random() * images.length);
index2 = Math.floor(Math.random() * images.length);
index3 = Math.floor(Math.random() * images.length);
index4 = Math.floor(Math.random() * images.length);
index5 = Math.floor(Math.random() * images.length);
document.getElementById('topAd1').innerHTML = images[index1];
document.getElementById('topAd2').innerHTML = images[index2];
document.getElementById('topAd3').innerHTML = images[index3];
document.getElementById('topAd4').innerHTML = images[index4];
document.getElementById('topAd5').innerHTML = images[index5];
}