This topic is locked

Range of Dates in a drop down box

1/13/2007 10:28:10 AM
ASPRunnerPro General questions
G
grinningdog author

I have a field that is a date of birth. I'm using a simple drop down box but the years suggested to me are 1997 - 2017. Because I want to limit the age of users I need the range to be 1935 - 1993. Is that possible?
I've got a second table where the age range should go from 1935 - 1997 (just in case that's relevant! ) <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=4372&image=1&table=forumtopics' class='bbc_emoticon' alt=';)' />
Regards

Bob

K
kerrykerzman 1/14/2007

I had the same problem and ended up switching to the single text box for my date of birth fields.

J
Jane 1/15/2007

Hi,
you can modify this in include/aspfunctions.asp file.
Find function name WriteYears(d, f), locate the following line:

for x=Year(d)-50 to Year(d)+50

and replace with required values of year. For example:

for x=1900 to 2050

G
grinningdog author 1/15/2007

Hi Jane
I tried this both with your example and the years I actually want but it seems stuck on 1997 - 2017

I've got:
[codebox]

Function WriteYears(d, f)

if f="" then

val=0

else

val=CLng(f)

end if

WriteYears = WriteYears & "<option value=""""> </option>"

for x=1900 to 2050
if x=val then

WriteYears = WriteYears & "<option value=" & x & " selected>" & x & "</option>"

else

WriteYears = WriteYears & "<option value=" & x & ">" & x & "</option>"

end if

next

end Function [/codebox]
I've tried it in IE Opera and Firefox but it doesn't seem interested in complying!
Bob

Sergey Kornilov admin 1/15/2007

Do I understand this correct you use For x=1900 to 2050 code and it displays years from 1997 to 2017?

G
grinningdog author 1/16/2007

Yes absolutely. I checked the code etc (the section above is a straight cut and paste from aspfunction.asp) I rebooted in case it was a cache thing, I even tried on another PC.

Do I understand this correct you use For x=1900 to 2050 code and it displays years from 1997 to 2017?

G
grinningdog author 1/16/2007

Errr... should I be in includes/commonfunctions.asp?
[codebox]' write years dropdown

function WriteYears(y)

ret="<option value=""""> </option>"

firstyear=year(now)-10

if y<>0 then

if firstyear>y-5 then firstyear=y-10

end if

lastyear=year(now)+10

if y<>0 then

if lastyear<y+5 then lastyear=y+10

end if

for i=firstyear to lastyear

s=""

if cstr(i)=cstr(y) then s="selected"

ret=ret & "<option value=""" & i & """ " & s & ">" & i & "</option>"

next

WriteYears = ret

end function[/codebox]

Sergey Kornilov admin 1/16/2007

Yes, this needs to be modified in include/commonfunctions.asp file.

Aspfunctions.asp is no longer in use. Sorry about confusion.

G
grinningdog author 1/17/2007

No problem at all. It works perfectly now.
Is it worth putting the aspfunctions file back to where it was or just ignore it?
Bob
PS For anyone else interested my code no reads:[codebox]' write years dropdown

function WriteYears(y)

ret="<option value=""""> </option>"

firstyear=year(now)-70

if y<>0 then

if firstyear>y-5 then firstyear=y-70

end if

lastyear=year(now)-12

if y<>0 then

if lastyear<y+5 then lastyear=y-12

end if

for i=firstyear to lastyear

s=""

if cstr(i)=cstr(y) then s="selected"

ret=ret & "<option value=""" & i & """ " & s & ">" & i & "</option>"

next

WriteYears = ret

end function[/codebox]

Sergey Kornilov admin 1/17/2007

Just ignore aspfunctions.asp for now. It will be gone in the next update.