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:
var date = new Date();
var currentDay = date.getDate();
var currentMonth = date.getMonth()+1;
var currentYear = date.getFullYear();
var dateString = currentYear +" "+format(currentMonth)+" ";
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;
<p><a id="link" href=""><img id="image" src="" /></a></p>
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.