Jul 04 2002

Filling a list with years

Posted by admin under Daterelated functions

<%
Sub Date_FillBoxWithYears( nFirst, nLast, nDefault )
Dim nYear
If nDefault = "" Then
nDefault = Date_GetYear( Now() ) 
End If 
For nYear = nFirst To nLast
Response.Write "<option" 
If nYear = nDefault Then
Response.Write " selected=yes"
End If
Response.Write ">" & nYear & "</option>"
Next
End Sub
%>
Fills a listbox with year numbers. You could specify interval by the nFirst and nLast parameters. nDefault tells which year should be preselected.

Usage:
<select size="1" name="FromYear">
<%
Date_FillBoxWithYears 1999, 2003, Date_GetYear( Now() ) 
%>
</select>