I do not know if you have already figured this out yourself but,
I kinda like that cartoon myself so I had a play at it.
The problem with your (
previous is undefined) error stems from trying to use a generic
window.onclick event handler when it would be more appropriate to just use a link or button to call your functions.
The two other problems I seen was your use of: getDay()
For your currentDay variable. This would return 0-6 and not the date (
1-31) which you would need.
The other problem was that you would need to add a leading zero to those dates which are less than 10.
Below is what I mashed together to fix those problems:
Code:
<html>
<head>
<title>FoxTrot Daily</title>
<script type="text/javascript">
<!--//
var date = new Date();
var currentDay = date.getDate();
var currentMonth = date.getMonth()+1;
var currentYear = date.getFullYear();
var dateString = currentYear +" "+format(currentMonth)+" ";
function format(number){
var zero="";
if(number<10) zero+="0";
return zero+number.toString();
}
function updateScreen(num){
currentDay = currentDay*1+num;
displayDate = dateString+" "+format(currentDay);
currentDate = dateString.replace(/\s/g,'').substring(2)+format(currentDay);
var theImg = 'http://www.msnbc.com/comics/comics/ft'+currentDate+'.gif';
var element = document.getElementById;
element('display').innerHTML = 'FoxTrot '+displayDate;
element('link').href = theImg;
element('image').src = theImg;
}
//-->
</script>
</head>
<body onload="updateScreen(0)">
<p id="display"></p>
<p><a href="javascript:updateScreen(-1)">Previous</a>
<a href="javascript:updateScreen(+1)">Next</a></p>
<p><a id="link" href=""><img id="image" src="" /></a></p>
<hr />
</body>
</html>
And if you look
here you will find an example which I put together which also fixes the problem of going backwards and forward between monthes and years.
.....Willy