473,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Random Image Script for more than one image slot

Greetings:

I have found a random image script that I like. It is located here:
http://www.javascriptcity.com/scripts/local/simage3.htm

I'd like to edit this to have 4 different slots for images with a
different set of 5 images for each slot, something like this page:
http://www.uchsc.edu

The script says /* no need to edit past this point (unless you want to
add more image slots) */

Does this mean that you can add more pictures to your array, or, that
you can add more image slots to your web site? Any thoughts on how to
edit this?

Or, do you have another script that can do the same thing? That is,
have random images for 4 different slots on one page? I have searched
a number of web sites and newsgroups and the script located above is
the closest I have found.

BTW; I tried copying and editing the script from the colorado page
http://www.uchsc.edu but couldn't get it to work.

TIA!

Linda

Jul 23 '05 #1
5 2555
Lee
Linda said:

Greetings:

I have found a random image script that I like. It is located here:
http://www.javascriptcity.com/scripts/local/simage3.htm


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",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
],
"two",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
],
"three",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
],
"four",
[ "http://www.azphx.com/dhtml/tmp/alpha6464.jpg",
"http://www.azphx.com/dhtml/tmp/beta6464.jpg",
"http://www.azphx.com/dhtml/tmp/gamma6464.jpg",
"http://www.azphx.com/dhtml/tmp/delta6464.jpg"
]
];
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="http://www.azphx.com/dhtml/tmp/alpha6464.jpg">
<h3>Two</h3>
<img id="two" src="http://www.azphx.com/dhtml/tmp/beta6464.jpg">
<h3>Three</h3>
<img id="three" src="http://www.azphx.com/dhtml/tmp/gamma6464.jpg">
<h3>Four</h3>
<img id="Four" src="http://www.azphx.com/dhtml/tmp/delta6464.jpg">
</body>
</html>

Jul 23 '05 #2
Linda wrote:
Greetings:

I have found a random image script that I like. It is located here:
http://www.javascriptcity.com/scripts/local/simage3.htm

I'd like to edit this to have 4 different slots for images with a
different set of 5 images for each slot, something like this page:
http://www.uchsc.edu
...


http://www.mickweb.com/javascript/ra...ageOnload.html
function displayRandomImage(imageName,array){
document.images[imageName].src=array[new Date().getTime()%array.length];
}
urls=["images/cs1.jpg","images/cs2.jpg","images/cs3.jpg","images/cs4.jpg"]

<body onload="displayRandomImage('csmember',urls)">
<!-- csmember is the NAME of the image receiving the random changes -->

//<img src="whatever.gif" name="csmember">

Get this working, and with a slight modification we can have as many
random images as you could possibly want.
Mick
Jul 23 '05 #3
Dear Lee!

Fabulous! What an elegent script - easy to read and edit! It's works
perfectly, thank you so much!

Jul 23 '05 #4
Hi Mick!

Thanks so much for responding. Your script is easy to use, and looks
great. The thing I wanted was more than one
image on the page that could be randomized. Check out what Lee posted.
It works great.

Thanks again for taking the time to respond to my request. I really
appreciate it!

Linda

Jul 23 '05 #5
Linda wrote:
Hi Mick!

Thanks so much for responding. Your script is easy to use, and looks
great. The thing I wanted was more than one
image on the page that could be randomized. Check out what Lee posted.
It works great.
Indeed it does, but I would use the document.images collection for
greater backwards compatibilty.
Mick

Thanks again for taking the time to respond to my request. I really
appreciate it!

Linda

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
6
by: Olly | last post by:
I've found a basic script, however I also need to add alt and title attributes as well, how would I go about doing this? Here's the script I found: Thanks <script language="JavaScript"> <!--...
6
by: lucy | last post by:
Hello comp.lang.js.I need a script to rotate a background image on each newpage load, given the id of the element and a list (array?)of 2 or more image paths ("img1.jpg", "img2.jpg", ...).Actually,...
15
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI...
23
by: Alvin | last post by:
Well, I'm developing a Tetris game in SDL, but when it comes to deciding the next block, I'm stuck. It's random, but when I try something like seeding the randomizer with the time, it won't update...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
4
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
1
by: bn4 | last post by:
I have been trying to modify a script that i had working in the past but have lost.. ORIGINAL URL: http://www.thescripts.com/forum/thread147097.html STEPS: I want it to do the following:...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.