Forum Moderators: open
image1.src="/images/evt_img/1.jpg"
image2.src="/images/evt_img/3.jpg"
image3.src="/images/evt_img/2.jpg"
image4.src="/images/evt_img/4.jpg"
image5.src="/images/evt_img/5.jpg"
image6.src="/images/evt_img/6.jpg"
image7.src="/images/evt_img/8.jpg"
image8.src="/images/evt_img/9.jpg"
*pseudo code bla bla*
for (i bla bla bal till 8) {
document.images.foo.src=eval("image"+i+".src")
}
Hello everyone, I was wondering if I can place the above declarations into a single array, and reference to it? I felt that this method is quite bulky and remembered that this can be simplified...
Thanks in advance for your help..
// An array to hold our image objects
var imageArray = [];
var i;
// Create 8 new Image objects
for (i = 0; i < 8; i++) {
imageArray[i] = new Image();
imageArray[i].src = "/images/evt_img/" + (i + 1) + ".jpg";
}
// Not sure exactly what you're trying to do here
// since 'foo' represents only a single image. This
// will just overright it with the images from our
// array, and it may happen too quickly to even notice
for (i = 0; i < imageArray.length; i++) {
document.images.foo.src = imageArray[i].src;
}
Edit: I just noticed that in your original post, your 7th and 8th images have a different name. Instead of 7.jpg and 8.jpg, you have 8.jpg and 9.jpg. Was that intentional? If so, then you'd need to modify the first for loop in my example to something like this:
// Create 8 new Image objects
for (i = 0; i < 8; i++) {
imageArray[i] = new Image();
imageArray[i].src = "/images/evt_img/" + (i < 7? i + 1: i + 2) + ".jpg";
}
[edited by: Fotiman at 3:16 pm (utc) on Nov. 6, 2007]