![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Posts: 7
Rep Power: 0
![]() |
Strange getMonth/setMonth problem
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... |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I find two references to "setMonth" in the code, both invocations. Where's the function definition?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2006
Posts: 7
Rep Power: 0
![]() |
http://developer.mozilla.org/en/docs...:Date:setMonth
It's part of the Date object. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2006
Posts: 7
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2006
Posts: 7
Rep Power: 0
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| strange problem | brad sue | C++ | 3 | Sep 1st, 2006 8:50 AM |
| Strange behavior: getting different results from the same input on a function. WTH? | pulpfiction | C | 1 | Mar 28th, 2006 11:43 PM |
| Strange Problem? | magic_e | PHP | 10 | Feb 9th, 2006 8:54 PM |
| cgi/perl script + IE problem | joyceshee | Perl | 2 | Jan 24th, 2006 11:10 AM |
| Variable array problem | Hintshigen | C | 6 | Apr 10th, 2005 2:35 PM |