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 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
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