|
Q458 How can you show a predetermined image for different days, but where the image filenames aren't consecutive?
irt.org | Knowledge Base | JavaScript | Image | Q458 [ previous next ]
Q458 How can you show a predetermined image for different days, but where the image filenames aren't consecutive?
By comparing the current date:
<script language="JavaScript"><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function padout(number) { return (number < 10) ? '0' + number : number; }
var today = new Date();
var year = y2k(today.getYear());
var month = padout(today.getMonth()+1);
var day = padout(today.getDate());
var today = '' + year + month + day;
var image = 'default.gif';
if (today == '19982507')
image = 'anynameinhere.gif';
else if (today == '19982607')
image = 'anothername.gif';
else if (today == '19982707')
image = 'anothername2.gif';
// ad nauseum
document.write('<img src="' + image + '" height="100" width="100"');
//--></script>
|
|
|
Copyright © 1996-2009 irt.org, All Rights Reserved.