Created
September 5, 2022 21:08
-
-
Save ash-f/b2baf102cf6dcb779297bb181d9e3650 to your computer and use it in GitHub Desktop.
fluent-forms-birthdate-calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calcAge($dob,$age){ | |
$dob.on('change', function() { | |
var dobary = $(this).val().split('/'); | |
var dobobj = new Date(dobary[2], dobary[0]-1, dobary[1]), birthday = { year: dobobj.getFullYear(), month: dobobj.getMonth(), date: dobobj.getDate() }; | |
var todayobj = new Date(), thisyear = todayobj.getFullYear(); | |
var thisYearsBirthday = new Date(thisyear, birthday.month-1, birthday.date); | |
var age = thisyear - birthday.year; | |
if(todayobj < thisYearsBirthday){ age--; } | |
$age.val(age); | |
}); | |
} | |
function bindEvents() { | |
var $dob1 = $form.find('#ff_3_date_of_birth'); | |
var $age1 = $form.find('#ff_3_age'); | |
calcAge($dob1,$age1); | |
} | |
bindEvents(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment