Page 1 of 1

Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 4:36 pm
by MackerelSky
Hi Steve/All,

I might have missed this in a search, but here goes

I've created a mwmonthlyrecordT.php and have it being processed by Cumulus and uploaded to my site as

http://www.mckeanweather.com/mwmonthlyrecord.php

It works great with all of the correct info inserted as far as I can tell.

My question, what would it take code wise to have it default to the current month that we are in instead of loading on the month of January.

I use the same script that comes inside the monthlyrecordT.htm file furnished from Steve

I've gotten the date_object.getMonth() to give me the correct month, ie: 0-11, currently (1) for February but I can't for the life of me figure out how to get it into the function changeData(month) or directly into the onclick="changeData(1)"

I'm just thinking that it would be nicer to load to the current month and maybe there could be other folks that would like the same thing. Would appreciate any help on the topic

Brad

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 5:00 pm
by mcrossley
A bit like mine?
http://weather.wilmslowastro.com/monthlyrecord.htm

Just need to put a call to changeData() at the end of the script...

changeData(+'<#month>' - 1);

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 5:02 pm
by steve
Mark has done that on his page: http://weather.wilmslowastro.com/monthlyrecord.htm

Edit: The forum didn't warn me that there had been another post (again).

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 6:09 pm
by MackerelSky
mcrossley wrote:A bit like mine?
Thanks Mark,

Even after your edit(lol) I couldn't get it to work...

Does it have something to do with the 'extra' code you have in your Page?

Code: Select all

function changeData(month) {
	for (fld in values) {
    if (fld.substring(0,4) === 'Rec_') {
      document.getElementById(fld).src = '/images/newRec-' + values[fld][month] + '.png';
    } else {
		  document.getElementById(fld).innerHTML = values[fld][month];
    }
	}

I understand that the code mainly has to do with your image for all time record but does it also do something for the current month?
Brad

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 6:22 pm
by mcrossley
I can't see what you have put in the source, but the effect is to produce this...

changeData(+'' - 1);

The month number is missing. Do you have the tag right? <#month>

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 6:25 pm
by mcrossley
Oh, and ignore my code, I have just streamlined the function a bit to loop through the spans rather than set them explicitly as the original code does.

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 6:28 pm
by mcrossley
Oh, one other thing, you need to move the script block from the page header to the end of the document, otherwise it will be trying to set the values before the browser has created them.

Re: Default to current month in monthlyrecord.htm

Posted: Sun 16 Feb 2014 7:00 pm
by MackerelSky
mcrossley wrote:Oh, one other thing, you need to move the script block from the page header to the end of the document, otherwise it will be trying to set the values before the browser has created them.
That's what was wrong, seems to be working now.

Thanks for your time

Brad

*edit*
Thanks to you too Steve