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.

  1. get year input - $('input').val().
  2. get current year - new date().getfullyear().
  3. 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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -