javascript - Age vertification input box - calculate if over 18 years -
i have input box should put year of birth in. if number below 1998 should gain access, if it's on 1998 should go page.
i know possible mixture of javascript , html, can't figure out how make code , hoped guys me!
this action should happen, if user born in 1998 or before:
<div id="btn-close-modal" class="close-modal-03"> close modal </div>
hope can me :-)
i'm using jquery.
- get year input -
$('input').val()
. - get current year -
new date().getfullyear()
. - check if diff between them larger 18.
like this:
$('#age_validation_btn').click(function() { var age = $('#age_validation_input').val(); if (new date().getfullyear() - parseint(age) >= 18) { alert('older 18'); } else { alert('younger 18'); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="number" id="age_validation_input" /><button id="age_validation_btn">validate</button>
Comments
Post a Comment