If you need to have people sign up that are currently between 14 and 40 it is not really cool to ask them how old are they now as next year they will have changed their age and you don’t want to have to ask them again. So here is an easy way to check what year they were born. This will allow you to check how old they are based on the year they were born.

Here is the code:

<SELECT SIZE=”1″ NAME=”year”>

<OPTION>Please select a year …</OPTION>
<% DIM intYearCounter, intCurrentYear %>
<% intCurrentYear = Year(Date) %>
<% FOR intYearCounter = (intCurrentYear – 40) TO (intCurrentYear – 14) %>
<% Response.Write “<OPTION>” & CStr(intYearCounter) & “</OPTION>” %>
<% NEXT %>
</SELECT>

The way it works is this:

Find the Current Year

<% intCurrentYear = Year(Date) %>

Then take the current year and loop through and find all the years between the two dates:

<% FOR intYearCounter = (intCurrentYear – 40) TO (intCurrentYear – 14) %>

Obviously you can change the dates and say, I want dates from 100 years ago to 5 years ago like this:

<SELECT SIZE=”1″ NAME=”year”>
<OPTION>Please select a year …</OPTION>
<% DIM intYearCounter, intCurrentYear %>
<% intCurrentYear = Year(Date) %>
<% FOR intYearCounter = (intCurrentYear – 100) TO (intCurrentYear – 5) %>
<% Response.Write “<OPTION>” & CStr(intYearCounter) & “</OPTION>” %>
<% NEXT %>
</SELECT>

It should look like this:

image

I hope that helps you.

About Paul Ogier

Paul Ogier has written 202 posts.

Paul Ogier is an IT Guru, Website Developer, and generally a nice guy. He loves code and he loves design.