The JavaScript Date Picker

33342 Users read it.
by Tom Dell'Aringa
Sooner or later you’re going to have the need for a user to fill in a field with a date. It’s like Murphy’s Law, it’s inevitable. In any event, one nice way of handling the situation is to provide some kind of widget to allow the user to pick the date instead of having them type the date in manually. Typing in dates manually can often be a problem, especially with a global medium like the web; Americans write 3 January 1/3; Europeans write 3/1. Are your dates 03/01/04? 3/1/04? 1/3/04? 1/3/2004? A date picker, when a user clicks on a date from a calendar-like interface can smooth the process.
 
Such a widget provides a couple of nice features. First of all, it helps you make sure the application gets good data. While it’s quite easy for the user to mistype a date, a correctly built script can place a correctly formatted date in your field 100% of the time.

This tutorial builds the Date Picker in JavaScript. You can cut and paste the code into your own appliciations.
User Rating (10 votes)
0 reviews available
$3.39 USD

User Level:Intermediate
Product:Visual Studio.NET, Web Matrix, CSharp Editor, Dreamweaver MX, Borland C#
Technologies:JavaScript
Number Of Pages:15

Table of Content:

  • How it looks
  • How it functions
  • Setup: HTML and CSS
  • Setting up the script
  • The main script
    • FormatDate()
    • Next and Previous
    • The First Day
    • Calendar Header
    • FormatRawDate()
    • Build the Calendar
    • Closing it up
    • The SelectDate() Function
    • Full Script Listing
  • Conclusion
  • Coda

Tom Dell'Aringa

Tom got his start in web development in the winter of 1995 when his boss threw an HTML book in his direction stating "we should learn about this world wide web thing." Since then he has worked at dot.com era start-ups with no real business model, web integrator Scient, and as a freelance and contracting developer. He is currently an Interaction Designer for ServiceMaster.

Experienced in HTML, JavaScript, and CSS as well as server-side scripting languages, he has worked on everything from simple brochure sites to enterprise level portals.

It was during one of these large projects that he finally got fed up with the "IE only" mentality of coding. Additionally, even large corporations seemed unaware of the benefits of separating style from content and still produced bloated, non-standard code. In response to this, and a corresponding discussion on Evolt's thelist (http://evolt.org), he founded MACCAWS (http://www.MACCAWS.org) in late 2002.

Lately part of his role on teams involves explaining to developers what LABEL tags are, that they shouldn't build layouts with tables nested ten levels deep, showing them alternatives to using 127 spacer gifs per page, proving the benefits of a global stylesheet and defining DOCTYPEs and how to use them.

He realized the dot.com era was over when his paychecks started bouncing right after the big welcome party he had been flown to in San Francisco. He currently resides in the Midwest with his wife and two children. He plays guitar and even recorded a demo CD with his band(http://www.garageband.com/artist/thestand). Constantly scouring Ebay and garage sales for Charlie Brown and Snoopy paperbacks, he is finding it very hard to find the Peanuts Parade versions...anyone..?

See All Postings From Tom Dell'Aringa >>

Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency