javascript, age, keydown

I already have onkeydown for one function called dateformat

My goal is if someone enter date format like 01/01/1972, it will call another function called 'CheckAge' and I want to show the value inside of the <div id="getage"></div>

How can i do that?


 function DateFormat(txt, keyCode) {
        if (keyCode == 16)
            isShift = true;
        //Validate that its Numeric
        if (((keyCode >= 48 && keyCode <= 57) || keyCode == 8 ||
             keyCode <= 37 || keyCode <= 39 ||
             (keyCode >= 96 && keyCode <= 105)) && isShift == false) {
            if ((txt.value.length == 2 || txt.value.length == 5) && keyCode != 8) {
                txt.value += seperator;
            }
            return true;
        }
        else {
            return false;
        }
    }

 function CheckAge(dateString)
    {
        if (dateString != '') {
            var today = new Date();
            var birthDate = new Date(dateString);
            var age = today.getFullYear() - birthDate.getFullYear();
            var m = today.getMonth() - birthDate.getMonth();
            if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
                age--;
            }
            alert(age);
        }
        else
        {
            alert("No Age");
        }
        return age;
        
    }

<div id=GetAge></div>
 <div class="ui-input">
											<input type="date" required tabindex="3" maxlength="10" name="dob" id="dob" onkeydown="return DateFormat(this, event.keyCode)" placeholder="Enter DOB" value="<%= GetDOB(Request.QueryString["Primary DOB"]) %>" class="form-control" />
											<label class="ui-icon"><i class="fa fa-birthday-cake"></i></label>
                                             <p id="exactAge"></p>
 										</div>

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITsolutionWizardAuthor Commented:
any helps?
Flabio GatesCommented:
try something like this
ITsolutionWizardAuthor Commented:
can you integrate your codes with my codes?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Flabio GatesCommented:
can you integrate your codes with my codes?
Unfortunately no since I have no idea what this is in your code:
<%= GetDOB(Request.QueryString["Primary DOB"]) %>

Open in new window

ITsolutionWizardAuthor Commented:
You can take off the value if it bothers you
Flabio GatesCommented:
You won't learn if you keep on asking people to do everything for you.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
 function DateFormat(txt, keyCode) {
        if (keyCode == 16)
            isShift = true;
        //Validate that its Numeric
        if (((keyCode >= 48 && keyCode <= 57) || keyCode == 8 ||
             keyCode <= 37 || keyCode <= 39 ||
             (keyCode >= 96 && keyCode <= 105)) && isShift == false) {
            if ((txt.value.length == 2 || txt.value.length == 5) && keyCode != 8) {
                txt.value += seperator;
            }
            return true;
        }
        else {
            return false;
        }
    }

 function CheckAge(dateString)
    {
    if (dateString != '') {
      var today = new Date();
      var birthDate = new Date(dateString);
      var age = today.getFullYear() - birthDate.getFullYear();
      var m = today.getMonth() - birthDate.getMonth();
      if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
      }
      return age;
    } else {
      return undefined;
    }
  }
  
$(document).ready(function(){
	$("#theButton").click(function() {
		$("#exactAge").text(CheckAge($("#dob").val()));
	})
});  

</script>
<div id=GetAge></div>
<div class="ui-input">
<input type="date" required tabindex="3" maxlength="10" name="dob" id="dob" placeholder="Enter DOB" class="form-control" />
<label class="ui-icon"><i class="fa fa-birthday-cake"></i></label>
<input type="button" value="click me" id="theButton" />
<p id="exactAge"></p>
</div>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Flabio GatesCommented:
Question inactive
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.