473,548 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2570
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.getEle mentById(d[i]).src=
d[i+1][Math.floor(Math .random()*d[i+1].length)];
}
}
</script>
</head>
<body onload="randomI mages(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 displayRandomIm age(imageName,a rray){
document.images[imageName].src=array[new Date().getTime( )%array.length];
}
urls=["images/cs1.jpg","image s/cs2.jpg","image s/cs3.jpg","image s/cs4.jpg"]

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

//<img src="whatever.g if" 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
9674
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 call that in another page so that i get a random image the page is http://2006ymcanationals.com/index.php using <img
6
3514
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
2082
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, depending on how I write the HTML, I guess I'dneed the script to set style.backgroundImage or src.I'd need to run it on a few elements, something...
15
3307
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 layer. EG. bits-layer 1. Any way, I want the quiz to reorder the problems each time I take it. Here is part of the code i did so far for 62 ...
23
2261
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 as fast as one block can fall, and the next to be determined. Generating different numbers in one spur can work, but people can play Tetris for...
4
2739
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is...
4
3066
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 image or save it. This is my first script so be gentle! Heres the script ####random group downloader#### import nntplib import string, random...
1
1959
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: 1-Load a Random Image each time page loads or is refreshed / script starts (with corresponding url link when clicked) 2-Images change by blend/fade into...
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.