Closed Thread Icon

Topic awaiting preservation: Image.SCR and FOR loops Pages that link to <a href="https://ozoneasylum.com/backlink?for=22865" title="Pages that link to Topic awaiting preservation: Image.SCR and FOR loops" rel="nofollow" >Topic awaiting preservation: Image.SCR and FOR loops\

 
Author Thread
jstuartj
Bipolar (III) Inmate

From: Mpls, MN
Insane since: Dec 2000

posted posted 08-09-2004 08:34

Ok I have a stupid question, I don't even have a clue, how to search for a solution.

I have the following code:

code:
function InitGallery(){

document.Thumb1.src = test[1].thumbnail.src
document.Thumb2.src = test[2].thumbnail.src;
document.Thumb3.src = test[3].thumbnail.src;
document.Thumb4.src = test[4].thumbnail.src;
document.Thumb5.src = test[5].thumbnail.src;
document.Thumb6.src = test[6].thumbnail.src;
document.Thumb7.src = test[7].thumbnail.src;
document.Thumb8.src = test[8].thumbnail.src;

}



How can I acomplish the same function using a FOR loop, Now I do understand FOR loops, and when I call the the above code from my body onLoad Event it works fine. But will need to acomplish the same function with in a loop to go any farther with my gallery script. What dont understand is how to deal with setting the "document.XXXXX.src" value with in a FOR loop.

I tried something like this:

document.Thumb(i).src = test[i].thumbnail.src;

and tried treating the 8 images similar to an array:

document.Thumb[i].src = test[i].thumbnail.src;

But I couldn't get it to work.

Could some explain or give an example on how to do this,

Here is my full code if it helps:

code:
// Add your gallery images here, up to 32 Images Total:
// Example: myRecord1 = new imgRecord (imgThumbnail, imgHighres, imgDescript);

var myPath = "Images/";

test = new Array(32);

test[0] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[1] = new imgRecord ("Event_002thumb.jpg","Event_002.jpg","My Image Description, Bla Bla Bla.");
test[2] = new imgRecord ("Event_003thumb.jpg","Event_003.jpg","My Image Description, Bla Bla Bla.");
test[3] = new imgRecord ("Event_004thumb.jpg","Event_004.jpg","My Image Description, Bla Bla Bla.");
test[4] = new imgRecord ("Event_005thumb.jpg","Event_005.jpg","My Image Description, Bla Bla Bla.");
test[5] = new imgRecord ("Event_006thumb.jpg","Event_006.jpg","My Image Description, Bla Bla Bla.");
test[6] = new imgRecord ("Event_007thumb.jpg","Event_007.jpg","My Image Description, Bla Bla Bla.");
test[7] = new imgRecord ("Event_008thumb.jpg","Event_008.jpg","My Image Description, Bla Bla Bla.");
test[8] = new imgRecord ("Event_009thumb.jpg","Event_009.jpg","My Image Description, Bla Bla Bla.");
test[9] = new imgRecord ("Event_010thumb.jpg","Event_010.jpg","My Image Description, Bla Bla Bla.");
test[10] = new imgRecord ("Event_011thumb.jpg","Event_011.jpg","My Image Description, Bla Bla Bla.");
test[11] = new imgRecord ("Event_012thumb.jpg","Event_012.jpg","My Image Description, Bla Bla Bla.");
test[12] = new imgRecord ("Event_013thumb.jpg","Event_013.jpg","My Image Description, Bla Bla Bla.");
test[13] = new imgRecord ("Event_014thumb.jpg","Event_014.jpg","My Image Description, Bla Bla Bla.");
test[14] = new imgRecord ("Event_015thumb.jpg","Event_015.jpg","My Image Description, Bla Bla Bla.");
test[15] = new imgRecord ("Event_016thumb.jpg","Event_016.jpg","My Image Description, Bla Bla Bla.");
//end of current Listing
test[16] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[17] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[18] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[19] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[20] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[21] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[22] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[23] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[24] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[25] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[26] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[27] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[28] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[29] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[30] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[31] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");
test[32] = new imgRecord ("Event_001thumb.jpg","Event_001.jpg","My Image Description, Bla Bla Bla.");

function imgRecord (imgThumbnail, imgHighRes, imgDescrip){

/*Fumction builds an image record object, holding thumbnail, highres
and image Description information; and preloads the images. */

if (document.images){

//Preload Thumbnail
aThumbnail = new Image (85,60);
aThumbnail.src = (myPath + imgThumbnail);

//Preload Highres
aHighRes = new Image (320,220);
aHighRes.src = (myPath + imgHighRes);

this.thumbnail = aThumbnail;
this.highres = aHighRes;
this.descrip = imgDescrip;
}
}

function InitGallery(){

document.Thumb1.src = test[0].thumbnail.src
document.Thumb2.src = test[1].thumbnail.src;
document.Thumb3.src = test[2].thumbnail.src;
document.Thumb4.src = test[3].thumbnail.src;
document.Thumb5.src = test[4].thumbnail.src;
document.Thumb6.src = test[5].thumbnail.src;
document.Thumb7.src = test[6].thumbnail.src;
document.Thumb8.src = test[7].thumbnail.src;
document.PlaceHolder.src = test[0].highres.src;

}




jstuartj

(Edited by jstuartj on 08-09-2004 08:40)

Jeffy
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Aug 2004

posted posted 08-09-2004 13:27

Try this as a solution - utilising eval().

code:
function InitGallery()
{
var _maxImages=8;
for (var loop=1;loop<=_maxImages;loop++)
eval("document.Thumb"+loop+".src="+test[loop].thumbnail.src)
}



You would change the _maxImages variable to contain the number of images you wish to "initialise". From your initial example I have set this to 8.

Enjoy,
Jeff

jstuartj
Bipolar (III) Inmate

From: Mpls, MN
Insane since: Dec 2000

posted posted 08-09-2004 14:28

aha, eval I new there was something I was missing. Thanks.


J. Stuart J.

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-09-2004 18:29

I've not tried it, but I'm guessing that this will also work, and allow you to remove the use of eval - which has a latency issue attached to it:

code:
document['Thumb'+loop].src=test[loop].thumbnail.src;



However, I'd say that either syntax (with or without eval) isn't 100% cross-browser (and possibly IE-only). I'd assign your images IDs and use getElementById to remain as cross-browser, cross-platform compatible as possible.

Hope this helps,
Dan

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 08-09-2004 18:35

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

« BackwardsOnwards »

Show Forum Drop Down Menu