Click to See Complete Forum and Search --> : JavaScript Calendar
lfparker
12-09-2002, 12:41 PM
Hi
I'm pretty new to JavaScript. I have some code that I downloaded from the internet that makes a clickable calendar that can be used to populate a text field with a date. The date is then passed to a SAS program using CGI. Problem is, when the user clicks on the icon, the calendar pops up and the current date is selected. I would like to have it so that the date selected on the from date calendar that pops up is January 2000 and the to date is the current date. Any ideas how I can change the code to accomplish this requirement? The code is attached. Thanks,
Lewis
Sceiron
12-10-2002, 02:50 AM
That's a hefty script you've got there. Anyway, some basic date functions should help you. You can create a date object and then set specific portions using...
var theDate = new Date();
theDate.setYear(2000);
theDate.setMonth(0); // Jan = 0
document.write(theDate.toString());
In the case of this script, it's a little more involved. I have not tested this, just so you know. Toward the bottom of the script, the default date is set right after the text "// no date set, default to today" which is where you will need to edit. It currently has...
var theDate = new Date();
this.year = this.oYear = theDate.getFullYear();
this.month = this.oMonth = theDate.getMonth();
this.day = this.oDay = theDate.getDate();
You should be able to change it to...
var theDate = new Date();
this.year = this.oYear = 2000;
this.month = this.oMonth = 0;
this.day = this.oDay = theDate.getDate();
And have it default to the current day of the month in Jan 2000. I hope that helps a little.
lfparker
12-10-2002, 07:01 AM
Sceiron - thanks for your help that did the trick.
Now, at the risk of being demanding, what if I had two text fields on my web page, the first being "from date" and the second being "to date". What I'm trying to do is make it easy for my users who are building a report. Since we are working with historical data, they would typically like to do date filtering by selecting a from date of Jan 1 2000 and a to date of December 31 2001 (for example). With this code change that you suggested, both boxes now default to January 1 2000. What I would really like to have it do is have the from date default to January 1 2000 and the to date default to December 31 2001. Any ideas? Thanks for your help and time,
Lewis.