Click here to Skip to main content
13,251,760 members (63,800 online)
Click here to Skip to main content
Add your own
alternative version


71 bookmarked
Posted 13 Oct 2005

JavaScript DatePicker

, 24 Feb 2006
Rate this:
Please Sign up or sign in to vote.
The DatePicker is a control for use on the client side of ASP.NET applications.

Sample Image - datepicker.gif


Here is the sample code for a DatePicker in JavaScript. It can be used on HTML pages or as an ASP control - like I use it (see demo files).

Here is the code snippet of the JS code (part of the "render" function):

DatePicker.prototype.render = function()
     var oT1, oTR1, oTD1, oTH1;
     var oT2, oTR2, oTD2;
     this.oSpan = document.getElementById(;
     this.oSpan.appendChild(oT1 = document.createElement("table"));
     oT1.width = "200";
     oT1.border = 1;
     oTR1 = oT1.insertRow(oT1.rows.length);
     oTD1 = oTR1.insertCell(oTR1.cells.length);
     oTD1.colSpan = 7;
     oTD1.className = 'DatePickerHdr';
     oT2 = document.createElement("table");
     oT2.width = "100%";
     oT2.border = 0;
     // New row.
     oTR2 = oT2.insertRow(oT2.rows.length);
     // Previous month.
     oTD2 = oTR2.insertCell(oTR2.cells.length);
     oTD2.title = this.texts.prevMonth;
     oTD2.onclick = function() { this.oDatePicker.onPrev(); }
     oTD2.oDatePicker = this;
     oTD2.innerHTML = "<img src="images/datepicker/prev.gif">";
     oTD2.className = 'DatePickerHdrBtn';
     // Month combo.
     oTD2 = oTR2.insertCell(oTR2.cells.length);
     oTD2.title = this.texts.monthTitle;
     this.oMonth = document.createElement("select");
     this.oMonth.oDatePicker = this;
     this.oMonth.onchange = this.oMonth.onkeyup = 
          function() { this.oDatePicker.onMonth(); }
     for(var i = 0; i < 12; i++)
        this.oMonth.add(new Option(this.texts.months[i], i),undefined);
     this.oMonth.className = 'DatePickerHdrBtn';
     // Year combo.
     oTD2 = oTR2.insertCell(oTR2.cells.length);
     oTD2.title = this.texts.yearTitle;
     this.oYear = document.createElement("select");
     this.oYear.oDatePicker = this;
     this.oYear.onchange = this.oYear.onkeyup = 
          function() { this.oDatePicker.onYear(); }

I did use Russian language and Russian date format because the need of the picker was for a Russian site. But the language and format the picker uses can be changed very simply - just change the array values and the "fill" method:

DatePicker.prototype.fill = function()
     // first clear all
     // place the dates in the calendar
     var nRow = 0;
     var d = new Date(this.dt.getTime());
     var m = d.getMonth();
     for ( d.setDate(1); d.getMonth() == m; 
           d.setTime(d.getTime() + 86400000) ) {
        var nCol = d.getDay();
        if(nCol == 0) nCol = 7;
        nCol = nCol-1;
        this.aCells[nRow][nCol].innerHTML = d.getDate();
        if ( d.getDate() == this.dt.getDate() ) {
           this.aCells[nRow][nCol].className = 
        if ( nCol == 6 ) nRow++;
     // set the month combo
     this.oMonth.value = m;
     // set the year text
     this.oYear.value = this.dt.getFullYear();

That is all. I do really think the control is very useful.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Nikita D. Sinelnikoff
Web Developer
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

Generalnice +5 Pin
Rajesh Biswas20-Jul-12 2:46
memberRajesh Biswas20-Jul-12 2:46 
Very nice...
GeneralMy vote of 4 Pin
skmm29-Jul-10 9:47
memberskmm29-Jul-10 9:47 
GeneralMy vote of 3 Pin
ramanarayananAsp8-Jul-10 7:35
memberramanarayananAsp8-Jul-10 7:35 
GeneralTwo Coordinated Dates Pin
krishna1122-Apr-08 20:55
memberkrishna1122-Apr-08 20:55 
GeneralEncapsulate this Class inside a Custom Control is done Pin
Stephan Pilz22-Sep-06 4:54
memberStephan Pilz22-Sep-06 4:54 
Questionabout date control Pin
disak22-Sep-06 20:14
memberdisak22-Sep-06 20:14 
AnswerRe: about date control Pin
Stephan Pilz24-Sep-06 21:15
memberStephan Pilz24-Sep-06 21:15 
GeneralRe: about date control Pin
disak24-Sep-06 22:32
memberdisak24-Sep-06 22:32 
GeneralRe: about date control Pin
Stephan Pilz25-Sep-06 0:03
memberStephan Pilz25-Sep-06 0:03 
GeneralRe: Encapsulate this Class inside a Custom Control is done Pin
shrirampophali29-Oct-07 22:19
membershrirampophali29-Oct-07 22:19 
GeneralRe: Encapsulate this Class inside a Custom Control is done Pin
shrirampophali29-Oct-07 22:20
membershrirampophali29-Oct-07 22:20 
Questionabout javascript Pin
disak22-Sep-06 2:14
memberdisak22-Sep-06 2:14 
GeneralSomebody is ripping you off Pin
WorkDoggy29-Aug-06 4:16
memberWorkDoggy29-Aug-06 4:16 
AnswerRe: Somebody is ripping you off Pin
Stephan Pilz7-Sep-06 4:59
memberStephan Pilz7-Sep-06 4:59 
GeneralRe: Somebody is ripping you off Pin
Guyon A. Roche7-Sep-06 11:41
memberGuyon A. Roche7-Sep-06 11:41 
AnswerRe: Somebody is ripping you off Pin
WorkDoggy8-Sep-06 2:10
memberWorkDoggy8-Sep-06 2:10 
GeneralRe: Somebody is ripping you off Pin
Guyon A. Roche8-Sep-06 11:53
memberGuyon A. Roche8-Sep-06 11:53 
GeneralRe: Somebody is ripping you off Pin
Stephan Pilz8-Sep-06 4:47
memberStephan Pilz8-Sep-06 4:47 
NewsThe coolest date-time picker is here Pin
kan_izh27-Feb-06 23:20
memberkan_izh27-Feb-06 23:20 
GeneralRe: The coolest date-time picker Pin
disak22-Sep-06 2:32
memberdisak22-Sep-06 2:32 
GeneralProvide us please with the proper encoding Pin
JailorSubRuberoid21-Feb-06 3:36
memberJailorSubRuberoid21-Feb-06 3:36 
AnswerRe: Provide us please with the proper encoding Pin
Nikita D. Sinelnikoff24-Feb-06 2:22
memberNikita D. Sinelnikoff24-Feb-06 2:22 
GeneralA Bugfix and some little extensions in Code Pin
Stephan Pilz20-Dec-05 21:33
memberStephan Pilz20-Dec-05 21:33 
GeneralRe: A Bugfix and some little extensions in Code Pin
Guyon A. Roche8-Sep-06 12:16
memberGuyon A. Roche8-Sep-06 12:16 
GeneralRe: A Bugfix and some little extensions in Code Pin
Stephan Pilz22-Sep-06 4:52
memberStephan Pilz22-Sep-06 4:52 
QuestionBase class? Pin
iammudman31-Oct-05 8:26
memberiammudman31-Oct-05 8:26 
AnswerRe: Base class? Pin
KamelJabber13-Mar-06 7:03
memberKamelJabber13-Mar-06 7:03 
Generalsome question! Pin
gyokusei16-Oct-05 1:38
membergyokusei16-Oct-05 1:38 
AnswerRe: some question! Pin
Nikita D. Sinelnikoff17-Oct-05 4:18
memberNikita D. Sinelnikoff17-Oct-05 4:18 
GeneralRe: some question! Pin
gyokusei18-Oct-05 20:30
membergyokusei18-Oct-05 20:30 
GeneralRe: some question! Pin
disak22-Sep-06 2:24
memberdisak22-Sep-06 2:24 
GeneralHTML version Pin
Steven A Bristol13-Oct-05 7:48
memberSteven A Bristol13-Oct-05 7:48 
GeneralRe: HTML version Pin
jsanjosem17-Oct-05 21:45
memberjsanjosem17-Oct-05 21:45 
GeneralRe: HTML version Pin
Steven A Bristol18-Oct-05 3:50
memberSteven A Bristol18-Oct-05 3:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 24 Feb 2006
Article Copyright 2005 by Nikita D. Sinelnikoff
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid