|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Age Group Calculator script help
Hi
I run an amature rugby site and am very new to programming. I need help to create a script for the site that can be used to tell what age group a person can join using there date of birth. The table for this years age groups are...... Quote:
Can anyone point me in the right direction? Regards in advance Mark |
|
#2
|
||||
|
||||
|
Age Group Calculator script help
i had an example of the same sort of thing, i edited it to point you in the right direction
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Age Group Calculator</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var monthArray = new Array("Jan (01)","Feb (02)","Mar (03)","Apr (04)","May (05)","Jun (06)","Jul (07)","Aug (08)","Sep (09)", "Oct (10)","Nov (11)","Dec (12)");
var currentDate = new Date();
var sy = (currentDate.getYear() - 6);
var sYear = (currentDate.getYear() - 8);
var eYear = (currentDate.getYear() - 18);
var yearDob;
var monthDob;
var dateDob;
var yearAge;
var groupArray = new Array(5);
groupArray[0] = new Array("U7","01/09/1",0,0,0);
groupArray[1] = new Array("U8","01/09/2","31/08/1","01/09/1","31/08/0");
groupArray[2] = new Array("U9","01/09/3","31/08/2","01/09/2","31/08/1");
groupArray[3] = new Array("U10","01/09/4","31/08/3","01/09/3","31/08/2");
groupArray[4] = new Array("U11","01/09/5","31/08/4","01/09/4","31/08/3");
groupArray[5] = new Array("U12","01/09/6","31/08/5","01/09/5","31/08/4");
groupArray[6] = new Array("U13","01/09/7","31/08/6","01/09/6","31/08/5");
groupArray[7] = new Array("U14","01/09/8","31/08/7","01/09/7","31/08/6");
groupArray[8] = new Array("U15","01/09/9","31/08/8","01/09/8","31/08/7");
groupArray[9] = new Array("U16","01/09/10","31/08/9","01/09/9","31/08/8");
groupArray[10] = new Array("U17","01/09/11","31/08/10","01/09/10","31/08/9");
groupArray[11] = new Array("U18","01/01/12","31/08/11","01/09/11","31/08/10");
function isLeap(theYear) {
if (theYear % 400 == 0) return true;
if (theYear % 100 == 0) return false;
if (theYear % 4 == 0) return true;
return false;
}
function ActionSelection(v, n) {
var rc = true;
if (n == "yearSel") {
if (v == "") {
document.frm1.monthSel.disabled = true;
ResetChild("monthSel");
yearDob = 0;
monthDob = 0;
dateDob = 0;
yearAge = 0;
}
else {
document.frm1.monthSel.disabled = false;
yearDob = v;
}
document.frm1.daySel.disabled = true;
ResetChild("daySel");
}
else if (n == "monthSel") {
if (v == "") {
document.frm1.daySel.disabled = true;
ResetChild("daySel");
monthDob = 0;
dateDob = 0;
yearAge = 0;
}
else {
document.frm1.daySel.disabled = false;
monthDob = v;
var td = Number(daysInMonth[monthDob]);
if (isLeap(yearDob) == true)
{
td += 1;
}
var dNum;
for (var r=1;r<=td;r++) {
dNum = (r < 10) ? "0"+r : r;
document.forms['frm1'].daySel.options[r] = new Option(dNum,r);
}
}
}
else if (n == "daySel") {
if (v == "") {
dateDob = 0;
yearAge = 0;
}
else {
rc = false;
dateDob = v;
}
}
else {
}
document.frm1.getAgeButton.disabled = rc;
document.frm1.txtAge.value = "";
}
function ResetChild(n) {
var selObj = document.getElementById(n);
selObj.selectedIndex = 0;
if (n == "daySel") {
document.frm1.daySel.options.length=1;
}
}
function PopulateData() {
//document.getElementById("clockspan").innerHTML = currentDate;
var d = 0;
for (var r=eYear;r<=sYear;r++) {
d += 1;
document.forms['frm1'].yearSel.options[d] = new Option(r,r);
}
var d = 0;
var mNum;
for (var r=0;r<=11;r++) {
d += 1;
mNum = (d < 10) ? "0"+d : d;
document.forms['frm1'].monthSel.options[d] = new Option(mNum,r);
}
document.frm1.monthSel.disabled = true;
document.frm1.daySel.disabled = true;
document.frm1.getAgeButton.disabled = true;
}
function CalculateAge() {
var yearNow = currentDate.getYear();
var monthNow = currentDate.getMonth();
var dateNow = currentDate.getDate();
yearAge = yearNow - yearDob;
if (monthNow >= monthDob)
var monthAge = monthNow - monthDob;
else {
yearAge--;
var monthAge = 12 + monthNow -monthDob;
}
if (dateNow >= dateDob)
var dateAge = dateNow - dateDob;
else {
monthAge--;
var dateAge = 31 + dateNow - dateDob;
if (monthAge < 0) {
monthAge = 11;
yearAge--;
}
}
document.frm1.txtAge.value = "Your current age is " + yearAge;
BuildTable();
}
function BuildTable() {
var tblSpan = "";
tblSpan = ("<table cellpadding='2' border='1'>");
tblSpan += ("<tr>");
tblSpan += ("<th>Age Group</th>");
tblSpan += ("<th>True Age Range</th>");
tblSpan += ("<th>Extra Age Range</th>");
tblSpan += ("</tr>");
var tempArray = groupArray[0][1].split("/");
var sTemp = tempArray[0] + "/" + tempArray[1] + "/" + (Number(sy) - Number(tempArray[2]));
var dd = (dateDob < 10) ? "0"+dateDob : dateDob;
var md = (Number(monthDob) + 1);
md = (md < 10) ? "0"+md : md;
var eTemp = dd + "/" + md + "/" + (Number(yearDob) + 6);
var hLight1 = CheckAgeGroup(sTemp, eTemp);
tblSpan += ("<tr>");
if (hLight1 == true) {
tblSpan += ("<td style='color:#ff0000;'>" + groupArray[0][0] + "</td>");
tblSpan += ("<td style='color:#ff0000;'>" + sTemp + " - " + eTemp + "</td>");
}
else {
tblSpan += ("<td>" + groupArray[0][0] + "</td>");
tblSpan += ("<td>" + sTemp + " - " + eTemp + "</td>");
}
tblSpan += ("<td> </td>");
tblSpan += ("</tr>");
for (var r=1;r<12;++r) {
var stArray = groupArray[r][1].split("/");
var sTemp = stArray[0] + "/" + stArray[1] + "/" + (Number(sy) - Number(stArray[2]));
var etArray = groupArray[r][2].split("/");
var eTemp = etArray[0] + "/" + etArray[1] + "/" + (Number(sy) - Number(etArray[2]));
var hLight1 = CheckAgeGroup(sTemp, eTemp);
var stArray2 = groupArray[r][3].split("/");
var sTemp2 = stArray2[0] + "/" + stArray2[1] + "/" + (Number(sy) - Number(stArray2[2]));
var etArray2 = groupArray[r][4].split("/");
var eTemp2 = etArray2[0] + "/" + etArray2[1] + "/" + (Number(sy) - Number(etArray2[2]));
var hLight2 = CheckAgeGroup(sTemp2, eTemp2);
tblSpan += ("<tr>");
if (hLight1 == true) {
tblSpan += ("<td style='color:#ff0000;'>" + groupArray[r][0] + "</td>");
tblSpan += ("<td style='color:#ff0000;'>" + sTemp + " - " + eTemp + "</td>");
tblSpan += ("<td>" + sTemp2 + " - " + eTemp2 + "</td>");
}
else if (hLight2 == true) {
tblSpan += ("<td style='color:#0000ff;'>" + groupArray[r][0] + "</td>");
tblSpan += ("<td>" + sTemp + " - " + eTemp + "</td>");
tblSpan += ("<td style='color:#0000ff;'>" + sTemp2 + " - " + eTemp2 + "</td>");
}
else {
tblSpan += ("<td>" + groupArray[r][0] + "</td>");
tblSpan += ("<td>" + sTemp + " - " + eTemp + "</td>");
tblSpan += ("<td>" + sTemp2 + " - " + eTemp2 + "</td>");
}
tblSpan += ("</tr>");
}
tblSpan += ("</table>");
document.getElementById("tableSpan").innerHTML = tblSpan;
}
function CheckAgeGroup(sDate, eDate) {
var dob = new Date(yearDob,monthDob,dateDob);
var sd = new Date(sDate.substring(6,10),sDate.substring(3,5)-1,sDate.substring(0,2));
var ed = new Date(eDate.substring(6,10),eDate.substring(3,5)-1,eDate.substring(0,2));
return (dob >= sd && dob <= ed) ? true : false;
}
// End -->
</script>
<style type="text/css">
.clockstyle {
color : #000000;
font-family: tahoma;
font-weight : bold;
}
.ageStyle {
padding-right: 20px;
}
.ageText {
border-left: solid 2px #ffffff;
border-right: solid 2px #ffffff;
border-top: solid 2px #ffffff;
border-bottom: solid 2px #ffffff;
color : #000000;
font-family: tahoma;
font-weight : bold;
font-size: 14px;
text-align: centre;
width: 170px;
}
</style>
</head>
<body onLoad="PopulateData()">
<p>
<span id="clockspan" class="clockstyle"></span>
</p>
<form name="frm1" id="frm1" action="" autocomplete="off" method="post">
<div>
<h3>Enter your date of birth to calculate the groups you can play in.</h3>
</div>
<div style="margin-top:20px;">
Enter your date of birth (yyyy/mm/dd):
<select name="yearSel" id="yearSel" onchange="javascript:ActionSelection(this[this.selectedIndex].value, this.name);">
<option value="">yyyy</option>
</select>
/
<select name="monthSel" id="monthSel" onchange="javascript:ActionSelection(this[this.selectedIndex].value, this.name);">
<option value="">mm</option>
</select>
/
<select name="daySel" id="daySel" onchange="javascript:ActionSelection(this[this.selectedIndex].value, this.name);">
<option value="">dd</option>
</select>
</div>
<div style="margin-top:20px;">
<span id="ageSpan" class="ageStyle">
<input type="text" name="txtAge" id="txtAge" class="ageText" readonly />
</span>
<button name="getAgeButton" id="getAgeButton" onclick="javascript:CalculateAge()">Get Age</button>
</div>
<div style="margin-top:20px;">
<span id="tableSpan"></span>
</div>
</form>
</body>
</html>
__________________
Hope this advise helps. ![]() If so please show your appreciation by adding reputation points (click gauge image on top right of this post and score).
|
|
#3
|
|||
|
|||
|
Cheers m8
will try it out Looks great, Many thanks for your time. Regards |
|
#4
|
|||
|
|||
|
Hi again
The script looks great, just tried it quickly and i noticed that the date on the U7s chages when you put in different years... Screenshots........ Cant up load them pm`d you the link to the screenshots (cant pm )The latest date that can be put in is 2001 12 31, this will only allow from The U8s True and U9s Extra I would like to understand the script if you have the time and patience to explain it to me (Total newbie to scripts) Is it also possible to change the date structure round? Ie. day month then year? Many thanks for your time Regards |
|
#5
|
||||
|
||||
|
Age Group Calculator script help
change the value of sYear in line 12 from -8 to -6
Code:
var sYear = (currentDate.getYear() - 6); |
|
#6
|
|||
|
|||
|
Quote:
Hi Did that, gave me the years but the U7s brought a strange number..... Age Group True Age Range Extra Age Range U7 01/09/2002 - 31/12/2009 It only seems to happen to the U7s age group, is this because there is no extra Date range unlike thye rest? what ever age group you are the u7s always changes the end date ? Regards |
|
#7
|
|||
|
|||
|
Hi
put in DOB 2003 12 31 - its says you are 5 but still highlights U7s As they are not 6, this should return a Too Young or is this not possible? Also is it possible that we could put any DOB in and if not eligable in the age groups, return the Too Old or Too Young ? appriciate your time an effort on this, its brilliant Regards Mark |
|
#8
|
|||
|
|||
|
Hi
Edited line 13 Quote:
this is the result Age Group True Age Range Extra Age Range U7 01/09/2002 - 01/01/1994 Says the person is 21, but the u7s age range changes again Regards |
|
#9
|
|||
|
|||
|
Hi
Noticed, the colours on the tables Red - true age range Blue - extra age range All text is black. What would i need to do to change colours? The website has a black background, so nothing would really show up. is it possible to put all this script in a frame on the website? Regards |
|
#10
|
||||
|
||||
|
Date Range
Hi
I assume that this is the dates the script works from Quote:
so braking it down Quote:
This is the U18s date layout 01/01/12 would be 2001/1st/dec (sorry, thats wrong - just noticed the year isnt done 91, 92 etc) can you explain please? am i correct? does the script have to work this way or can it be altered to dd/mm/yyyy? I have noticed that sometimes, if a person has the same year and month, the date can not be entered. if you change the month and back it will work Regards |
|
#11
|
||||
|
||||
|
Age Group Calculator script help
what i did was made it dynamic so:
date layout 01/01/12 would be 2001/1st/dec is not what it is the format is: day/month/off set numbers of year from current year |
|
#12
|
|||||
|
|||||
|
Quote:
What would i alter for next season in the date range? Quote:
Quote:
Cheers for your time Regards |
|
#13
|
||||
|
||||
|
Age Group Calculator script help
you shouldn't have to alter anything as the year value is an off set value from the current year not a year value, so it's dynamic and will calc the without change
|
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Age Group Calculator script help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|