/    Sign up×
Community /Pin to ProfileBookmark

date calculation in forms

Is it possible to input a date in a form that uses the system date to calculate a persons age?

If that is possible, how can I set an alert if the age does not fall between an upper and lower age limit eg 18 to 30?

I can sort out the input for the date and I can automatically set ‘today’s date’ in another field, but thereafter it gets a bit foggy – hope someone can help please.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@requestcodeAug 18.2003 — Here is a link to a script that calculates your age in different units. Maybe it will help:

http://www.javascriptkit.com/script/script2/agefind.shtml
Copy linkTweet thisAlerts:
@janixauthorAug 19.2003 — Thanks, that has helped a little but I'm still not sure how to set up an alert if someone falls outside the age range.
Copy linkTweet thisAlerts:
@GollumAug 19.2003 — well if...
<i>
</i>var now = new Date();
// and
var birthday = new Date(y,m,d);
// then
var age = now.getYear() - birthday.getYear();
var tmp = new Date(now.getYear(),m,d);
if ( tmp.getTime() &gt; now.getTime() ) age--;
// so
if ( (age &lt; 18) || (age &gt;= 31) ) alert("You're either too old or too young to enjoy this holiday package.");
×

Success!

Help @janix spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...