Click to See Complete Forum and Search --> : Advanced question???


kpowning
02-16-2003, 03:11 PM
Ok, I have a rotating images script and it works for all my pages in the root directory, but when I put one of my pages in another folder, the image rotation is disabled. Any ideas to how I can fix that? The script is listed below.. Lets say that the new folder is "email" for an example..

//<script language="JavaScript">
function LoadImg() {
var n=0;
var a=null;
var imgs = new Array();
/* enter list of image locations below */
var locs = ["img/r_img/img001", "img/r_img/img002", "img/r_img/img003", "img/r_img/img004", "img/r_img/img005", "img/r_img/img006", "img/r_img/img007", "img/r_img/img008", "img/r_img/img009", "img/r_img/img010"];

n = locs.length;
n = Math.floor(Math.random() * n);
document.img1.src=locs[n] + "_01.jpg";
//document.img2.src=locs[n] + "_02.jpg";
}

Antithesis
02-16-2003, 03:20 PM
You need to put the locations of all the images in relation to the root directory...

var locs = ["/img/r_img/img001", "/img/r_img/img002", "/img/r_img/img003", "/img/r_img/img004", "/img/r_img/img005", "/img/r_img/img006", "/img/r_img/img007", "/img/r_img/img008", "/img/r_img/img009", "/img/r_img/img010"];

Nedals
02-16-2003, 06:34 PM
Try something like this..

var imagepath = "../img/r_img/"; // if moving one directory level
OR
var imagepath = "http://www.domain.com/img/r_img/"; // more general and probably prefered!!


var locs = ["img001", "img002", "img003", "img004", "img005", "img006", "img007", "img008", "img009", "img010"];

....

document.img1.src = imgpath + locs[n] + "_01.jpg";

kpowning
02-16-2003, 06:49 PM
Thanks for everyone's help, however I figured it our how to make it work..

Thanks again...