Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Javascript
Random Image Script for more than one image slot
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Lee, post: 4881227"] Linda said: That script does a bad job of generating random numbers. You can replace "one", "two", "three", and "four" with the id values of your images, and replace the list of URLs under each one with the URLs that you want to select from for that image. In this example, they're all the same because I ran out of demo images. You have add any number of images with any number of URLs for each one: <html> <head> <script type="text/javascript"> var data = [ "one", [ "[URL]http://www.azphx.com/dhtml/tmp/alpha6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/beta6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/gamma6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/delta6464.jpg[/URL]" ], "two", [ "[URL]http://www.azphx.com/dhtml/tmp/alpha6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/beta6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/gamma6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/delta6464.jpg[/URL]" ], "three", [ "[URL]http://www.azphx.com/dhtml/tmp/alpha6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/beta6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/gamma6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/delta6464.jpg[/URL]" ], "four", [ "[URL]http://www.azphx.com/dhtml/tmp/alpha6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/beta6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/gamma6464.jpg[/URL]", "[URL]http://www.azphx.com/dhtml/tmp/delta6464.jpg[/URL]" ] ]; function randomImages(d) { for(var i=0;i<d.length-2;i+=2) { document.getElementById(d[i]).src= d[i+1][Math.floor(Math.random()*d[i+1].length)]; } } </script> </head> <body onload="randomImages(data)"> <h3>One</h3> <img id="one" src="[URL]http://www.azphx.com/dhtml/tmp/alpha6464.jpg[/URL]"> <h3>Two</h3> <img id="two" src="[URL]http://www.azphx.com/dhtml/tmp/beta6464.jpg[/URL]"> <h3>Three</h3> <img id="three" src="[URL]http://www.azphx.com/dhtml/tmp/gamma6464.jpg[/URL]"> <h3>Four</h3> <img id="Four" src="[URL]http://www.azphx.com/dhtml/tmp/delta6464.jpg[/URL]"> </body> </html>[/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Javascript
Random Image Script for more than one image slot
Top