Results 1 to 6 of 6
  1. #1
    New Member
    Join Date
    Sep 2012
    Location
    The Missouri Ozarks
    Posts
    2

    How to Display a Random Image With Hyperlink

    I hope I have the right forum for this:

    I've used this Media College page http://www.mediacollege.com/internet...ndom-link.html to display a series of hyperlinked images. I have it working well enough, but I want it to repeat the code several times on the same page within different cells of a frame.

    As I say, the first example works fine, but subsequent ones aren't visible. What am I doing wrong?

    (Here's the sample code from the page linked above)

    <script type="text/javascript">
    var total_images = 3;
    var random_number = Math.floor((Math.random()*total_images));
    var random_img = new Array();
    random_img[0] = '<a href="page1.html"><img src="images/image1.gif"></a>';
    random_img[1] = '<a href="page2.html"><img src="images/image2.gif"></a>';
    random_img[2] = '<a href="page3.html"><img src="images/image3.gif"></a>';
    document.write(random_img[random_number]);
    </script>

  2. #2
    Administrator Dave's Avatar
    Join Date
    Sep 2004
    Location
    Te Awamutu, New Zealand
    Posts
    3,959
    Blog Entries
    79
    It should work. Can you show us the URL so we can get some idea of what might be wrong?
    Dave Owen
    MediaCollege.com

  3. #3
    New Member
    Join Date
    Sep 2012
    Location
    The Missouri Ozarks
    Posts
    2
    Quote
    Quote: Dave
    View Post
    It should work. Can you show us the URL so we can get some idea of what might be wrong?
    Yes (sorry to have dropped the ball) it is: http://homestead.org/NewIndexes/new-MainOpener.htm

  4. #4
    Administrator Dave's Avatar
    Join Date
    Sep 2004
    Location
    Te Awamutu, New Zealand
    Posts
    3,959
    Blog Entries
    79
    It works fine for me. Have you tried reloading the page?
    Dave Owen
    MediaCollege.com

  5. #5
    Want to randomly dispay images and hyperlinks from a list? No problem, you can do it with a simple script like the one shown here. No need to learn server-side scripting, or slow down your pages with full-blown Java applications. The script shown below randomly loads an image from the list you input each time a page is loaded into a browser.

  6. #6
    Administrator Dave's Avatar
    Join Date
    Sep 2004
    Location
    Te Awamutu, New Zealand
    Posts
    3,959
    Blog Entries
    79
    Quote
    Quote: nexlar
    View Post
    The script shown below randomly loads an image from the list you input each time a page is loaded into a browser.
    Sorry, if you try post code without the [CODE] tags it will be automatically be stripped.
    Dave Owen
    MediaCollege.com

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
  •  
Subscribe to us on YouTube