var $j = jQuery.noConflict();
$j(function() {
function leadingZero(num) {
return (num < 10 ? '0' : '') + num;
}
// event when season year selector changes
$j('#season').change(function() {
// show all the years ages again
$j('.age-eligible').show();
// hide the error message
$j('#ll-ineligible').hide();
});
$j('#get-age').click(function() {
var
now = new Date(),
birthdate = $j('#bday').val() + 'T' +
leadingZero(now.getHours()) + ':' +
leadingZero(now.getMinutes()) + ':00',
date = new Date(birthdate),
monthCol = date.getMonth() + 1,
birthYear = date.getYear() + 1900,
$table = $j('#ll-age-' + $j('#season option:selected').val()),
// get all the cells in the column
$monthCells = $table.find('tbody tr td:nth-child(' + monthCol + ')'),
cellLen = $monthCells.length,
match = false
;
$monthCells.each(function(index) {
// match the year in the lookup table
if ($j(this).text() == birthYear)
{
var
// find the row
row = index + 1,
// get the last value in the row (the age)
age = $table.find('tbody tr:nth-child(' + row + ') td:last-child').text()
;
// hide all the ages
$j('.age-eligible').hide()
// show just the age
.filter('#ll' + age + '-eligible').show();
// hide the age tables
$j('.ll-age').hide();
match = true;
}
if (index === cellLen - 1) {
if (!match) {
// hide all the ages
$j('.age-eligible').hide()
// show just the age
.filter('#ll-ineligible').show();
}
}
});
});
// run after page loads
$j(function() {
var
// get the current year
currentYear = (new Date).getFullYear()
;
// select the current year in the Season dropdown
$j('#season option[value=' + currentYear + ']').attr('selected','selected');
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.