PDA

View Full Version : Random Background Image



DowntownEER
08-10-2006, 05:56 PM
I have nine images that I'd like to assign as random background images in a table.

Can anybody help with that?

Thanks!

mburt
08-10-2006, 06:42 PM
This uses a random number, and an array of images to show a random background color for a table.


<html>
<head>
<script type="text/javascript">
var images = new Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg","image6.jpg","image7.jpg","image8.jpg","image9.jpg")
onload=function() {
var rand = Math.round(Math.random()*images.length-1)
table1.style.background="url('"+images[rand]+"')"
}
</script>
</head>
<body>
<table id="table1"></table>
</body>
</html>