View Full Version : Random Images with Text for Each Image

06-16-2004, 11:48 PM
<td height="400" colspan=2 background=" Change This Image ">
<table width="688" height="400" border="0" cellpadding="0" cellspacing="0">
<td height="300" colspan="6" align="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td valign="top"> Text based on image Goes here </td>

I have in the past used to change my images using this script.

<SCRIPT LANGUAGE="Javascript">
function image() {

image = new image();
number = 0;

// imageArray
image[number++] = "<td height='400' colspan=2 background='1.jpg' border='0' height='249' width='491'>"
image[number++] = "<td height='400' colspan=2 background='2.jpg' border='0' height='249' width='491'>"
image[number++] = "<td height='400' colspan=2 background='3.jpg' border='0' height='249' width='491'>"
increment = Math.floor(Math.random() * number);


I am trying to figure out how to change text with the images. However the text isn't right next to the image but in a table cell.
I tried if else statements and failed. Any Suggestions on how to accomplish this.

06-17-2004, 05:14 AM
<script type="text/javascript">
function setImage(){
var arrImg = new Array();
arrImg[0] = new Object();
arrImg[0].src = "image1.gif";
arrImg[0].text = "This is image 1";

arrImg[1] = new Object();
arrImg[1].src = "image2.gif";
arrImg[1].text = "This is image 2";

arrImg[2] = new Object();
arrImg[2].src = "image3.gif";
arrImg[2].text = "This is image 3";

//...and so on

var idx = Math.floor(Math.random()*arrImg.length);

document.getElementById('colImage').style.backgroundImage='url(' + arrImg[idx].src + ')';
<body onload="setImage()">
<td id="colImage" colspan="2" style="height:400px;background-image:url(default.gif)">
<td valign="top" id="colText">Text for the default image background</td>

07-07-2004, 08:42 PM
I thought I would post what I did with this code.

Check it out at http://www.sundanceresort.com/test.html

07-07-2004, 10:22 PM
Hi colorspots:

I would only further suggest that you reference the images sequentially...with such a small collection. Only if you had 10 or 20 images, would random display be practical.


Thanks, Glenn.

07-07-2004, 10:25 PM
I have considered that. I am planning on using 10-20 different images and messages. I feel the sequential the last images/message will get less exposure so I thought randomizing it allowed more variation of viewing.