Debt Consolidation - Creative Electronics - Debt Consolidation - Novated lease - Find jobs

PDA

View Full Version : random image


rojojat
Dec 15th 2008, 9:39 am
Hi,
I am looking for a javascript code that will display a different image each time the web page is displayed, or refreshed.
Thanks.

astupidname
Dec 16th 2008, 1:54 pm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dumb Title</title>
<script type="text/javascript">
/*<![CDATA[*/

function myRandomImg(id) {
var pics = ["images/1m.gif", "images/2m.gif", "images/3m.gif", "images/4m.gif", "images/5m.gif"];
var rNum = Math.floor(Math.random() * pics.length);
document.getElementById(id).src = pics[rNum];
}

window.onload = function () {
myRandomImg('randImg');
};

/*]]>*/
</script>
</head>
<body>
<div>
<img src="images/1m.gif" alt="1m.gif" id="randImg" />
</div>
</body>
</html>

rojojat
Dec 17th 2008, 9:42 am
Thank You.