Results 1 to 2 of 2

Thread: Multiple random Image Script

  1. #1
    Join Date
    Sep 2010

    Multiple random Image Script

    Hi all,

    I have tried to make sense of other posts but can't, and was wondering if anyone can assist me.

    What I would like is two have two image containers on seperate parts of a page, both randomising every load.

    My current code is:

    <script type="text/javascript" language="JavaScript">
    <!-- Copyright 2002 Bontrager Connection, LLC
    // Type the number of images you are rotating.
    NumberOfImagesToRotate = 35;
    // Specify the first and last part of the image tag.
    FirstPart = '<img src="/Images/Randomised/image';
    LastPart = '.jpg">';
    function printImage() {
    var r = Math.ceil(Math.random() * NumberOfImagesToRotate);
    document.write(FirstPart + r + LastPart);
    I hope someone can hope...


  2. #2
    Join Date
    Jan 2009
    ok i think what you need to do is make an array and a random number picker. each entry should reference a different picture. the code below isn't entirely mine and is psuedo code so don't just try to copy and paste. i do understand it even though it's not entirely mine so if you have questions fire away.

    var randomPics= new array;
    randomPics[0] = /Images/Randomised/image1.gif;
    randomPics[1] = /Images/Randomised/image2.gif;
    randomPics[34] = /Images/Randomised/image34.gif;
    randomPics[35] = /Images/Randomised/image35.gif;
    <script type="text/javascript" language="javascript">
    { if (Math.random) return Math.round(Math.random() * (range-1)); 
    else { var now = new Date(); return (now.getTime() / 1000) &#37; range; } } // Write out an IMG tag, using a randomly-chosen image name. 
    var choice = pickRandom(ic); // --> 
    <SCRIPT LANGUAGE="JavaScript">
    document.writeln('<TD'+'><IMG SRC="'+randomPics[choice]+'" HEIGHT=184 WIDTH=120 BORDER=0 ><'+'/TD>');

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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