Forum Moderators: open

Message Too Old, No Replies

Random backgrounds in tables

Random backgrounds in tables

         

Soulfound

2:18 pm on Sep 22, 2004 (gmt 0)



I have been trying to decipher several scripts trying to show how to show a random image inside a table when a page is refreshed. I am very very very stuck. I used some code from an old post (see below):

<html>
<head>
<title></title>
<style type="text/css">
#bgChange {
background-image:url(/images/staff/index_staff_001.jpg);
}
</style>
<script type="text/javascript">
function random_image()
{
image_array = new Array();
image_array[0] = '/images/staff/index_staff_002.jpg';
image_array[1] = '/images/staff/index_staff_003.jpg';
image_array[2] = '/images/staff/index_staff_004.jpg';

count = image_array.length;
random = Math.floor(Math.random() * count);

document.getElementById('bgChange').style.backgroundImage = "url(" + image_array[random] + ")";
}
</script>
</head>
<body onload="random_image();">
<table id="bgChange" width="400" height="400">
<tr>
<td>&nbsp;</td>
</tr></table>
</body>
</html>

I need help! This doesn't work when I put the scripts in the actual HTML file that I need it to work in.

adni18

4:26 pm on Sep 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Works fine for me. Make sure your images are in the correct folder.