Date Select Dropdown Example
Updated 12/09/2001: Fixed inline script bug in Netscape 6.x browsers that prevented the date object from being initialized properly. This caused invalid date selection to be posted if the default value of the date drop downs were used.
This example dynamically builds drop down date selection objects on an ASP page. Returning valid dates from a client's browser has always been a problem. Was a valid date entered, is the client's date format MM/DD/YYYY or DD/MM/YYYY. The solution used here is to create three seperate dropdown objects for month, day and year. A hidden object type is also created to hold the selected date. The date format returned to the server is selectable.
To generate the dropdown date selection objects is as simple as calling a subroutine from your script:
GenDateDropDown(objref, objname, setdate, begyear, endyear, datemode) 'Parameters: ' objref = object's form reference ' objname = date selection object name ' creates three dropdowns for day, month and year ' dropdown names will be the objname plus d, m and y added as a suffix ' a hidden object of the objname is created to hold the selected date ' setdate = default date selection ' begyear = minimum year range in year drop down, values prior to 1970 not allowed ' endyear = maximum year range in year drop down ' datemode = determines date format returned in the hidden object's value ' datemode = 1 - MM/DD/YYYY ' datemode = 2 - DD/MM/YYYY ' datemode = 3 - YYYYMMDD ' datemode = 4 - universal formatExample: GenDateDropDown "document.forms[0]", "date1", date(), 1990, 2020, 1