Web Analytics Made Easy -
StatCounter arrays - CodingForum

Announcement

Collapse
No announcement yet.

arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • arrays

    hello, i am trying to call new images from my js code, but the trouble I am having is ::: i want to add an array of values so i can call different images into different areas.. at the moment I have done it like this... just repeating the code

    var preload = new Image();
    preload.src = "../images/leftblock_bot.gif";

    function GIFS() {
    document['botleft'].src = preload.src;
    }
    var preload = new Image();
    preload.src = ".../images/top_blockleft.gif";

    function GIFS() {
    document['mainleft'].src = preload.src;
    }

    but this is long and sloppy, is there an easier way to say i want this named id to call this image using more than one var ??

    thank you chris

    <marquee>thanks</marquee>

  • #2
    Code:
    function gifSwitcher(image, source) {
        document.images[image].src = source;
        }
    var pics = [ ['botleft', "../images/leftblock_bot.gif"], ['mainleft', "../images/top_blockleft.gif"] ];
    
    for ( var i = 0; i < pics.length; i++) {
        gifSwitcher(pics[i][0], pics[i][1]);
    }
    i think that's what you were asking for. it makes the function gifSwitcher, which takes the argument of which image to switch, and the picture it should be switched to. then, you create a 2 column array. the first column is the name of the picture to switch, and the second column is the source of the picture to switch to. then, using a for-next loop, you run through this entire array, assigning its contents to the gifSwitcher.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment

    Working...
    X