![]() |
Strange getMonth/setMonth problem
1 Attachment(s)
Ok, the code is attached, and you can use it by adding onfocus="cal.showCal(this);" to any text input like this:
:
<input name="demo" type="text" maxlength="10" size="10" onfocus="cal.showCal(this);" />Anyway, It sounds easy, but I tried manually changing the adjustment in the Calendar.prototype.changeMonth function like this: :
this.current.setMonth(this.current.getMonth()+1);:
this.current.setMonth(this.current.getMonth());:
this.current.setMonth(this.current.getMonth()-1);Anyway, the problem is that creating a test case didn't seem to work...I couldn't repeat the glitch. Maybe someone can find my glaring error? I know that this system worked not that long ago...I HAVE made changes, but I have no idea where this went wrong... |
I find two references to "setMonth" in the code, both invocations. Where's the function definition?
|
http://developer.mozilla.org/en/docs...:Date:setMonth
It's part of the Date object. |
1 Attachment(s)
I've used alerts, and console.logs all over the place, and I'm still lost. One thing I DO know is that the function isn't running twice. It only runs once. I log the adjustment (1 or -1 as expected), I run getMonth (0-11, and always as expected), I log the math (-1 - 12, and again as expected), and then I setMonth, and log getMonth...and it's OFF!
Summary: I'm still lost. I'm attaching 3 files... the .js, the .css, and a .html that will let you test it. |
As it turns out, the date that I was adjusting was Month/LastDayOfMonth/Year, so it would be something like: 10/31/2006 and it would try to change it to 11/31/2006 (which doesn't exist, 11 only has 30 days). It doesn't know what to do with that, so it interprets it as 12/01/2006. I simply added this.current.setDate(1); before the setMonth and it worked perfectly.
|
| All times are GMT -5. The time now is 2:11 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC