Click to See Complete Forum and Search --> : multiple random image question
haasboy
07-17-2003, 09:25 PM
This is probably very simple, but thanks for any help.
I have a javascript which creates a random image in a web page. If I want to set up another array in the head content which will target a separate holder script in the body how do I differentiate them. Not sure if I'm explaining this well.
Thanks again
Exuro
07-17-2003, 09:52 PM
No, that wasn't very clear at all, but I think I might get what you're saying anyway... Just give the array a different name, and that should solve your problem I think. But if you really want help you should probably either post your code or a link to it or something....
Charles
07-18-2003, 04:56 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
<script type="text/javascript">
<!--
Array.prototype.random = function () {return this[Math.round (Math.random() * Math.ceil (this.length / 10) * 10) % this.length]}
// -->
</script>
<h1>Example</h1>
<script type="text/javascript">
<!--
document.write('<img alt="[Bettie in a Bikini]" src="', ['http://www.bettiepage.com/images/photos/bikini/bikini1.jpg', 'http://www.bettiepage.com/images/photos/bikini/bikini2.jpg', 'http://www.bettiepage.com/images/photos/bikini/bikini3.jpg', 'http://www.bettiepage.com/images/photos/bikini/bikini4.jpg'].random(), '">');
// -->
</script>
<noscript><img alt="[Bettie in a Bikini]" src="http://www.bettiepage.com/images/photos/bikini/bikini1.jpg"></noscript>
<script type="text/javascript">
<!--
document.write('<img alt="[Bettie with a Whip]" src="', ['http://www.bettiepage.com/images/photos/whip/whip1.jpg', 'http://www.bettiepage.com/images/photos/whip/whip2.jpg', 'http://www.bettiepage.com/images/photos/whip/whip3.jpg', 'http://www.bettiepage.com/images/photos/whip/whip4.jpg'].random(), '">');
// -->
</script>
<noscript><img alt="[Bettie with a Whip]" src="http://www.bettiepage.com/images/photos/whip/whip1.jpg"></noscript>
haasboy
07-18-2003, 06:55 AM
Thanks for the responses and I;ll try to see if the posted script can work better for me. I am posting the script. I have this script in the head
<SCRIPT language=JavaScript>
var theImages = new Array()
theImages[0] = '1.gif'
theImages[1] = '2.gif'
theImages[2] = '3.gif'
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}
</SCRIPT>
And this in the body.
<SCRIPT language=JavaScript>
showImage();
</SCRIPT>
I want to set up a seperate array of images in the head which would populate a seperate area of the page. So I would have multiple random image areas on the page. I don't know how to distinguish them so that 2 scripts in the head will populate 2 seperate regions on the page with random images. Thanks for patience and help.