Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q458 How can you show a predetermined image for different days, but where the image filenames aren't consecutive?

You are here: irt.org | FAQ | JavaScript | Image | Q458 [ previous next ]

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>

©2018 Martin Webb