View Full Version : java script. nearly there, but need a lil help

01-11-2006, 12:17 AM
<span style='color:red'>edited by dj as it broke the forum</span>

Hi again all.
Im having trouble with a javascript.
so far it works good and what it basically does is: Makes the banner image of the homepage sequentially change (i++) every 5secs with 4 images being used.

Is there a way to tell the js that;
IF this page X loads
LOAD this image Array []
execute function

so in essence have an array of images for each page.
below is working code:

var imageArry = Array('ctnt_pic_home_graduation.jpg','ctnt_pic_hom e_jimmy.jpg',
'ctnt_pic_home_restaurant.jpg','ctnt_pic_home_trai nees.jpg');
var currentImage = "ctnt_pic_home_graduation.jpg";

// generates a random image from a selection of 4 images
function generateRandomImage() {
var docPath = "common/images/";

for(var i=0; i < imageArry.length; i++) {
if(currentImage == "") {
currentImage = imageArry[i];
i = imageArry.length;
} else if(currentImage == imageArry[imageArry.length-1]) {
currentImage = imageArry[0];
i = imageArry.length;
} else {
if(currentImage == imageArry[i]) {
currentImage = imageArry[(i+1)];
i = imageArry.length;
document.getElementById("featureImage").src = docPath + currentImage; // changes the image src for feature image

01-11-2006, 07:48 AM
do you have the function in every page or are you calling the javascript in as a src file

Creative Insanity
01-11-2006, 08:33 AM
edited by dj as it broke the forum
aggghhh! chris you broke the forum! You know I hate broken forums.. good move on the edit dj as I would of gone nuts if I saw that.

anyhoo off topic so back on track.

01-12-2006, 10:58 PM
sorry i forgot.. i fixed the prob few days ago. so much stuff going on.
close thread