JavaScript Hands-on 3

index.html
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head></head>
<body>
<div id="app">
<form onsubmit="return getAge()">
<label>Enter your DOB:</label>
<input type="date" id="dob" name="dob">
<input type="submit" value="submit">
<p id="showresults"></p>
</form>
</div>
<script src="index.js" type="text/javascript"> </script>
</body>
</html>
--------------------------------------------------
--------------------------------------------------
index.js
--------------------------------------------------
---------------------------------------------------
function getAge() {
var age=document.getElementById("dob").value;
var l=age.toString();
var kk= l.substring(0,4);
var year=parseInt(kk);
var d= new Date();
var n=d.getFullYear();
var k=n.toString();
var m=parseInt(k);
if(year>=m){
document.getElementById("showresults").innerText="Wrong date!!";
}
else{
document.getElementById("showresults").innerText="You are "+(m-year)+" year(s) old!!";
}
}

 

©2018 by The real one. Proudly created with Wix.com