javascript: date-conditional image swapping

Message Bookmarked
Bookmark Removed
i have 12 images,one for each month. they're named things like "images/tab_apr_off.gif" , where "apr" changes to "mar" or even "dec", if you know what i mean. they also have "_on.gif" versions. what i want is to change the appropriate month's graphic to its on state when the page loads.

caveat: I DON'T KNOW HOW TO PROGRAM.

the following is what i come up with and it doesn't work. the function is called from an onLoad statement in the body tag.



function setNav() {

var monthnames=null;
var Today = null;
var thisMonth = null;


var monthnames = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
var Today = new Date();
thisMonth = monthnames[Today.getMonth()];

document.all.[thisMonth].src = "images/tab_" + thisMonth + "_on.gif"

}

Tracer Hand (tracerhand), Thursday, 3 April 2003 20:18 (twenty-one years ago) link

i doubt i even need the "null" thingies; i was told once that it "helps"

Tracer Hand (tracerhand), Thursday, 3 April 2003 20:18 (twenty-one years ago) link

i think that setNav may be expecting an object or argument and not getting it

lord kno i sure don't

Tracer Hand (tracerhand), Thursday, 3 April 2003 20:26 (twenty-one years ago) link

I don't really know javascript, but that [thisMonth] in the last line looks a bit random to me

RickyT (RickyT), Thursday, 3 April 2003 20:39 (twenty-one years ago) link

thisMonth is a variable, it's supposed to be the month number translated into the array i've set up at the beginning; 0-12 = jan-dec

i know i'm not doing it right, though..... aaaaagh!!

Tracer Hand (tracerhand), Thursday, 3 April 2003 20:44 (twenty-one years ago) link

i am totally waiting for titters from the savvy

Tracer Hand (tracerhand), Thursday, 3 April 2003 20:44 (twenty-one years ago) link

See my post in ILE.

Paul Eater (eater), Thursday, 3 April 2003 20:47 (twenty-one years ago) link

How about something like:

<script language="JavaScript"><!--
var day = new Date();
var month = day.getMonth() + 1;
var image = 'images/' + month + '_on';

for (i = 1; i < 13; i++) {
if (i == month) {on = 'on_';} else {on = 'off_';}
document.write('<img src="' + i + on + '.jpg"><br>');
}
//--></script>

Paul Eater (eater), Thursday, 3 April 2003 21:10 (twenty-one years ago) link



onClick="var time = new Date();var hours = time.getHours();var minutes = time.getMinutes();minutes=((minutes < 10) ? '0' : '') + minutes;var seconds = time.getSeconds();seconds=((seconds < 10) ? '0' : '') + seconds;var clock = hours + ':' + minutes + ':' + seconds;document.forms['timer'].display.value = clock;return false;">

Alan (Alan), Friday, 11 April 2003 15:25 (twenty-one years ago) link





Alan (Alan), Friday, 11 April 2003 15:25 (twenty-one years ago) link





Alan (Alan), Friday, 11 April 2003 15:26 (twenty-one years ago) link


You must be logged in to post. Please either login here, or if you are not registered, you may register here.