CoderZone.org

Category: >> ASP/VB Code >> Date Picker Form in ASP Bookmark and Share

<< lastnext >>

Snippet Name: Date Picker Form in ASP

Description: Make a nice date-picker form in ASP, with dropdowns for the month, day, and year.

Also see:
» Calculate days between any two dat...
» Convert Minutes to Days, Hours, an...
» Get Easter Date for any year in Ja...
» Get last and next months with ASP
» Sort A File List By Month Name In ...
» Time left In Weeks, Days, Hours, A...
» Check whether a date belongs to a ...
» Get Date 30 days ago
» Date: Find first day of the month
» Date Functions: NEXT_DAY
» Date Functions: MONTHS_BETWEEN
» Date Functions: LAST_DAY
» Date Functions: ADD_MONTHS
» Detect Leap Year
» Create monthly partitions
» Define schedule of holidays
» Month, Day, Year dropdown boxes
» Random banner picker
» Calculate date of Easter Sunday
» Define a schedule of holidays
» Calendar for any month any year
» Detect Daylight Saving Time
» Add or Subtract days
» Fast random row picker #2
» Fast random row picker #1
» Months_Between function
» Last_Day function
» Date Functions: Add Months
» Avoid overlapping months and years

Comment: (none)

Author:
Language: ASP
Highlight Mode: ASP
Last Modified: December 04th, 2010

<%
Function MonthSelector
Response.Write "<select name='month' id='month'>"
Response.Write "<option value = '01'>01</option>"
Response.Write "<option value = '02'>02</option>"
Response.Write "<option value = '03'>03</option>"
Response.Write "<option value = '04'>04</option>"
Response.Write "<option value = '05'>05</option>"
Response.Write "<option value = '06'>06</option>"
Response.Write "<option value = '07'>07</option>"
Response.Write "<option value = '08'>08</option>"
Response.Write "<option value = '09'>09</option>"
Response.Write "<option value = '10'>10</option>"
Response.Write "<option value = '11'>11</option>"
Response.Write "<option value = '12'>12</option>"
Response.Write "</select>"
End Function
 
Function DaySelector(MaxDay)
'Pass an empty string if you 
'want to use the default value
'of 31 for MaxDay
 
if not isNumeric(MaxDay) then
	MaxDay = 31
elseif cint(MaxDay) < 1 or (MaxDay) > 31 then
        MaxDay = 31
elseif MaxDay < 28 then 
    MaxDay = 28
end if
 
Response.Write "<select name='Day' id='Day'>"
For iCtr = 1 to MaxDay
      Response.Write "<option value = '" & iCtr & "'>"
      Response.Write iCtr & "</option>" & vbCrlf
Next      
Response.Write "</select>"
End Function
 
 
Function YearSelector(BeginYear, EndYear)
'Pass "" for parameters if you want default values of 1900 and current year
 
If Not isNumeric(BeginYear) then
     BeginYear = 1900
elseif BeginYear > Year(Now) or cint(BeginYear) < 0 then
     BeginYear = 1900
else
     BeginYear = cint(BeginYear)
End if
 
If Not isNumeric(EndYear) then
     EndYear = Year(Now)
elseif EndYear < BeginYear then
     EndYear = Year(Now)
else
     EndYear = Cint(EndYear)
end if
 
Response.Write "<select name='Year' id='Yesr'>"
For iCtr = BeginYear to EndYear
       Response.Write "<option value = '" & iCtr & "'>"
       Response.Write iCtr & "</option>" & vbCrlf
Next      
Response.Write "</select>"
 
End Function
 
'Sample form and usage:
%>
<html><body>
<% if request("cmdSubmit") = "" then %>
<b>Please select a date:</b>
<form name="datepicker" action="testpage.asp">
<table>
<tr>
<td><B>Month:</td><td><%MonthSelector%></td>
<td><B>Day:</td><td><%DaySelector "" %></td>
<td><B>Year:</td><td><%YearSelector "", ""%></td>
</tr>
</table><P>
<input type="submit" name="DateSubmit" id="DateSubmit" value="Go">
</td><tr>
</table>
</form>
 
 
<%
else
 
sDate = Request("Month") & "/" & Request("Day") & "/" & Request("Year")
  if isDate(sDate) then %>
      <B>Success- you entered a valid date.</B>
  <% else %>
  <B>You entered a invalid date.</B>
  <% end if %>
 <P><a href='testpage.asp'>Enter another date:</a>
 
<% end if %>
 
</body></html>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 5