SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot cckrocks's Avatar
    Join Date
    Nov 2000
    Location
    A home in the hills where the grass grows green an
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using this script to randomly display a menu item. I would like to be able to use this throughout my document with the same array, just a random picture in each place. how could I modify this code to be able to do this? Currently, I'm using the script locally in the body. I would like to have a script in the head of the document and then use the array in different places. Here is the code:

    Code:
    <script type="text/javascript">
    <!--
    var imagesArray = new Array(
    "image1.gif",
    "image2.gif",
    "image2.gif"
    );
    var index = Math.floor(Math.random() * imagesArray.length);
    document.write("img src=" + imagesArray[index] + ".");
    // -->
    </script>
    Thanks for any help!!!
    Think beyond what is common...
    www.jaggedknife.com
    www.fusion-in.com

  2. #2
    SitePoint Zealot cckrocks's Avatar
    Join Date
    Nov 2000
    Location
    A home in the hills where the grass grows green an
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No takers?????
    Nevermind, I figured it out...
    Set your array in the head, and then use this code wherever you want the random image:

    Code:
    <script type="text/javascript">
    var index = Math.floor(Math.random() * imagesArray.length);
    document.write("img src=" + imagesArray[index] + ".")
    </script>
    Think beyond what is common...
    www.jaggedknife.com
    www.fusion-in.com

  3. #3
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cckrocks,

    Independance is a beautiful thing, isn't it?
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •