Jason Moon's Fool-Proof Date Input Calendar Script

 

Required client-side JavaScript include:

<script type="text/javascript" src="calendarDateInput.js"></script>

Create the calendar-control by calling the "DateInput" function. Parameters are:

  1. DateName - STRING - required; name of the hidden form element to store the selected, formatted date
  2. Required - BOOLEAN - optional; default = FALSE
  3. DateFormat - STRING - optional; default is set as a global variable in the script (MM/DD/YYYY on this page)
  4. DefaultDate - STRING - optional; default = current system date from the client PC

Supported date formats:

*   2-digit year can be used instead of 4-digit year
** 3-character month name abbreviation can also be specified as MMM

Working Examples:

Jason's Anniversary:
Called like this: <script>DateInput('anniversary', false, 'DD-MON-YYYY', '28-JUN-2003')</script>
 
Button action: onClick="alert(this.form.anniversary.value)"
 
Isabella's Birthday:
Called like this: <script>DateInput('isabella_birth', true, 'YY/DD/MM', '05/13/04')</script>
 
Button action: onClick="alert(this.form.isabella_birth.value)"
 
Independence Day:
Called like this: <script>DateInput('independence', false, 'YYYY-MM-DD', '1776-07-04')</script>
 
Button action: onClick="alert(this.form.independence.value)"
 
Today:
Called like this: <script>DateInput('today', true)</script>
  (formatted in this page's default date format: MM/DD/YYYY)
Button action: onClick="alert(this.form.today.value)"
 
Your Birth Date:
Called like this: <script>DateInput('your_birth', false, 'DD-MON-YY')</script>
 
Button action: onClick="alert(this.form.your_birth.value)"
 
Missing 1st Parameter:
Called like this: <script>DateInput()</script>

Access via JavaScript:

calendarDateInput.js Customizable variables: