Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

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

Avatar of ITsolutionWizard
ITsolutionWizard
Flag of United States of America image

ASKER

any helps?
Avatar of Flabio Gates
Flabio Gates

try something like this
can you integrate your codes with my codes?
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

You can take off the value if it bothers you
ASKER CERTIFIED SOLUTION
Avatar of Flabio Gates
Flabio Gates

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Question inactive