0

basically I am setting up a age verification script for a alcohol company and each country of course has a specific age to consume or buy alcohol.

I have set up the basics just now but I am running in to a problem. Right now I want to be able to gather there DOB using the input fields. Convert this to a date and them somehow compare it to the legal drinking age of the country in question.

Unfortunately testing the DOB is proving difficult and I know it is a problem with the event handler I am using as it won't output my required result to the console.

If anyone could help that would be fantastic.

Here is a link to my fiddle.

var countries = {
    "Albania": 18,
    "Algeria": 18,
    "Argentina": 21,
    "Armeria": 18,
    "Australia": 18,
    "Austria": 18
};

var individualCountry;
var day;
var month;
var year;

$("#verify").submit(function() {

    day = $("#day").val();
    month = $("#month").val();
    year = $("#year").val();

    var fullDate = day + month + year;
    console.log(fullDate);


    individualCountry = $("#countries").val();
    var ageLimit = countries[individualCountry];
    if (personsAge >= ageLimit) {

    }


})

https://jsfiddle.net/h989qrLs/

Harry Berry
  • 65
  • 10

1 Answers1

0

try this code

function_calculateAge(birthday) { // birthday is a date
    var ageDifMs = Date.now() - birthday.getTime();
    var ageDate = new Date(ageDifMs); // miliseconds from epoch
    return Math.abs(ageDate.getUTCFullYear() - 1970);
}

for more details open this link by André Snede Hansen

Community
  • 1
  • 1
Poula Adel
  • 609
  • 1
  • 10
  • 33