JavaScript Calendar Script/Date Picker Widget
There are many javascript calendar widgets(or date pickers) out there - so I decided to make another one. Yes, I have a really bad case of 'Not-Invented-Here' syndrome...
Demo
Download the Code
Features
- Simple
- Supports multiple calendars on one page
- Self contained - don't need an external library
- Unobtrusive - even if JavaScript is off, you still get basic functionality(the date input box is shown)
- Display style can be easily configured by editing the stylesheet
Disadvantages(or To Do List)
- New script - expect bugs
- Only English/Gregorian calendar supported.
- No API support.
- Date format for the input box cannot be configured(yet)

Comments
<html>
<head>
<script src="calendar.js" type="text/javascript"></script>
<link href="calendar.css" type="text/css" rel="stylesheet" />
</head>
<body>
<input type="text" name="date" id="date" />
<script type="text/javascript">
calendar.set("date");
</script>
</body>
</html>
Your date picker is great!
Can you tell me how to change the javascript so that the date format is mm-dd-yyyy?
Not a big deal, but if it is not a difficult change that would be great.
Thanks!
See Brian at 26 Jul, 2009 09:35 topic.
Thx in advance!
I also fix some little bugs, but any way lots of thX to the author of this simple but grate script.
Cheers,
tedd
i have a small doubt can i stop the date selection to the current date,
if so plz provide the script.
Thank you once again to give such a nice code.....
I needed the date to read like this: 12th March 2010 so I did the following (probably very clumsy!)...
FIRST, find the line that reads: var ths = _calendar_active_instance;
PASTE the following lines, right after it. They help you to use the full month name in the input field (January in stead of 01, February instead of 02 etc.) and also put the 'th' or 'st' in 12th or 21st etc.
var themonthname = parseInt(month-1);
var thedaynum = parseInt(day);
var ordinal = '';
if (thedaynum == 1 || thedaynum == 21 || thedaynum == 31) {
ordinal = 'st'
}
else if (thedaynum == 2 || thedaynum == 22 ) {
ordinal = 'nd';
}
else if (thedaynum == 3 || thedaynum == 23) {
ordinal = 'rd';
}
else {
ordinal = 'th';
}
NEXT change the line that says: document.getElementById(ths.opt["input"]).value = year + "-" + month + "-" + day;
to THIS: document.getElementById(ths.opt["input"]).value = day + ordinal + " " +this.month_names[themonthname]+ " " + year;
NEXT find this: selected_date = new Date(date_parts[0], date_parts[1], date_parts[2]);
and change to THIS: selected_date = new Date(date_parts[2], date_parts[1], date_parts[0]);
That makes sure that the right day is selected on the calendar, if you open it again after selecting a day.
LASTLY you can find this line: if(w < 10) w = "0" + w;
and put // in front of it, so it reads like this: //if(w < 10) w = "0" + w;
That's optional, but it stops the dates having a zero in front of them (02nd January 2010 looks ugly, this will make it 2nd January 2010)
As I said, I'm not a Javascript coder, so that may not be the best way of doing things, but it does work. Hopefully that can help someone else use this great script! :)
You need to find THIS line: var date_parts = date_in_input.split(" ");
change it to THIS: var date_parts = cleandate.split(" ");
and paste the following right ABOVE it:
var cleandate = date_in_input.replace("th","").replace("st","").replace("nd","").replace("rd","").replace("January","1").replace("February","2").replace("March","3").replace("April","4").replace("May","5").replace("June","6").replace("July","7").replace("August","8").replace("September","9").replace("October","10").replace("November","11").replace("December","12");
that reverses the nice formatting, and turns it back into a number, so the script can correctly highlight the date from the input box.
I only share this in the hope that it might help a fellow newbie - not claiming it's the best or brightest way to do things, it just worked for me, that's all. :)
Ur DatePicker is really superb....but i found a flaw in that... i.e the value of the test box doesn't changes with the new date...ple update..i am in need of that..
thanks in Advance
regards
kapil
It is really excellent. Can u please update if u have worked on the above points mentioned
Date format need in MM-dd-yyyy
Please update as i need it. Thanks in advance
a, strong, em, b, i, code, pre, pandbrallowed. Other tags will be shown as code(< will become <). Urls, Line breaks will be auto-formated.