hello,
i found a script to display a daily rotated image which i was hoping to use on my site. after copying the code into a page and setting up the the images in the format dd_mm.jpg, i can't seem to get it to work. the page displays a broken image link. the code for the page is below:
Code:
<html>
<head>
<title>Today's Found Object...</title>
<script language="javascript" type="text/javascript">
function loadImage()
{
var today = new Date();
var imgString = today.getDate()+"_"+today.getMonth()+".jpg";
document.getElementById("foundobject").src = imgString;
}
</script>
</head>
<body bgcolor="#CCCCCC" onLoad="loadImage();">
<img src="" id="foundobject" alt="Today's Found Object...">
</body>
</html>
the problem is that the returned value of getDate() and getMonth() are without leading zeros!
so, imgString today will contain somthing like: 6_9.jpg (note that the month offset starts from 0 instead of 1)
so here is the script after modifications:
Code:
<html>
<head>
<title>Today's Found Object...</title>
<script language="javascript" type="text/javascript">
function loadImage()
{
var today = new Date();
var day = today.getDate();
var month = today.getMonth();
if (day < 10)
day = "0" + day;
month++;
if (month < 10)
month = "0" + month;
var imgString = day + "_" + month +".jpg";
document.getElementById("foundobject").src = imgString;
}
</script>
</head>
<body bgcolor="#CCCCCC" onLoad="loadImage();">
<img src="" id="foundobject" alt="Today's Found Object...">
</body>
</html>
__________________ PHPSimplicity
We don't need a reason to help people - Zidane [FF9]