user2129560
user2129560

Reputation: 37

ASP date array (vbscript)

How would I set up an array to write out the year in a drop down list from current year and back 50 years?

What I have now:

<select name="Year">
<option selected>--Year--</option> 
<% If Month(Now) = 12 Then %>
<option value="<%=Year(Now) +1 %>"><%=Year(Now) +1 %></option>                
<% End If %>                   
<option value="<%=Year(Now)%>"><%=Year(Now)%></option>

Upvotes: 0

Views: 502

Answers (1)

kloarubeek
kloarubeek

Reputation: 2844

<%
Const cNumberOfYears = 50
Dim nCount
Dim nYear: nYear = Year(Now)
%>
<select name="Year">
<%
For nCount = 0 To cNumberOfYears - 1
    Response.write "<option value=""" & (nYear - nCount) & """>" & (nYear - nCount) & "</option>"
Next
%>
</select>

update: just realized it can be done much simpler, saving you a variable ;-)

Upvotes: 1

Related Questions