Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Random Image Generator problem

    I found a nice script I'd like to use on a client's site (pasted below) The idea is to generate three random images on the home page that are linked to various site pages. This one allows me to define separate images for each of the three arrays. A link to the working script is here .
    Code:
    <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
    <!-- Hide script from old browsers
    myPix1 = new Array("images/pathfinder.gif","images/surveyor.gif","images/surveyor98.gif")
    myPix2 = new Array("images/callisto.jpg","images/europa.jpg","images/io.jpg","images/ganymede.jpg")
    
    function choosePix() {
    	if (document.images) {
    		randomNum = Math.floor((Math.random() * myPix1.length))
    		document.myPicture1.src = myPix1[randomNum]
    
    		randomNum = Math.floor((Math.random() * myPix2.length))
    		document.myPicture2.src = myPix2[randomNum]
    		}
    	}
    
    // End hiding script from old browsers -->
    </SCRIPT>
    </HEAD>
    <BODY BGCOLOR="WHITE" onLoad="choosePix()">
    <IMG SRC="images/spacer.gif" WIDTH="201" HEIGHT="155" NAME="myPicture1" ALT="some image"><br><br>
    <IMG SRC="images/spacer.gif" WIDTH="262" HEIGHT="262" NAME="myPicture2" ALT="some image">
    However, I can't seem to get the thing to work on my site. The only thing I did was add another array and plug in my images. Only the transparent "space.gif" is loading. Here's my .js file:

    Code:
    <!-- Hide script from old browsers
    	myPix1 = new Array("image/hollandth.jpg","image/nationalth.jpg","image/brennanth.jpg")
    	myPix2 = new Array("image/nationalth.jpg","image/brennanth.jpg","image/hollandth.jpg")
    	myPix3 = new Array("image/brennanth.jpg","image/hollandth.jpg","image/nationalth.jpg")
    
    	function choosePix() {
    		if (document.images) {
    			randomNum = Math.floor((Math.random() * myPix1.length))
    			document.myPicture1.src = myPix1[randomNum]
    
    			randomNum = Math.floor((Math.random() * myPix2.length))
    			document.myPicture2.src = myPix2[randomNum]
    			
    			randomNum = Math.floor((Math.random() * myPix3.length))
    			document.myPicture3.src = myPix3.randomNum]
    		}
    	}
    	// End hiding script from old browsers -->
    And here's what's in the html:

    Code:
    <td><IMG SRC="image/space.gif" WIDTH="158" NAME="myPicture1" ALT="some image"></td>
    <td><IMG SRC="image/space.gif" WIDTH="158" NAME="myPicture2" ALT="some image"></td>
    <td><IMG SRC="image/space.gif" WIDTH="158" NAME="myPicture3" ALT="some image"></td>
    I don't understand why the example code works just fine, yet my nearly identical code doesn't. Any ideas? Sharper eyes?

    Thanks in advance,
    Tim

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by junip


    Code:
    <!-- Hide script from old browsers
    	myPix1 = new Array("image/hollandth.jpg","image/nationalth.jpg","image/brennanth.jpg")
    	myPix2 = new Array("image/nationalth.jpg","image/brennanth.jpg","image/hollandth.jpg")
    	myPix3 = new Array("image/brennanth.jpg","image/hollandth.jpg","image/nationalth.jpg")
    
    	function choosePix() {
    		if (document.images) {
    			randomNum = Math.floor((Math.random() * myPix1.length))
    			document.myPicture1.src = myPix1[randomNum]
    
    			randomNum = Math.floor((Math.random() * myPix2.length))
    			document.myPicture2.src = myPix2[randomNum]
    			
    			randomNum = Math.floor((Math.random() * myPix3.length))
    			document.myPicture3.src = myPix3.randomNum]
    		}
    	}
    	// End hiding script from old browsers -->
    Change the part I put in red to myPix3.randomNum or myPix3[randomNum] instead of myPix3.randomNum]
    Oh, was I supposed to put something here? ........

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops! I didn't see that...

    Tried it and it still didn't work. Now I'm using a different script from willy and its working. Only that one won't seem to work with IE. I'm getting a little frustrated now, but at least my css is validated!

    Thanks!

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by junip
    Whoops! I didn't see that...

    Tried it and it still didn't work. Now I'm using a different script from willy and its working. Only that one won't seem to work with IE. I'm getting a little frustrated now, but at least my css is validated!

    Thanks!
    I wrote that script using IE6 so there is no reason why it shouldn't work unless you are using an older version of IE which does not support the javascript array push() method...

    .....Willy

  • #5
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Willy Duitt
    I wrote that script using IE6 so there is no reason why it shouldn't work unless you are using an older version of IE which does not support the javascript array push() method...

    .....Willy
    I think that is pretty much exactly the case. Unfortunately, the version I'm using (IE 5.2.3) is the latest version available for mac. I really don't feel like reverse-engineering your script to make it work, so unless you already know how, I'm just going to add a browser detect script or something to send people to a basic html version of the page.

    Thanks anyway.

    Tim


  •  

    Posting Permissions

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