i am trying to develop a children magazine website and making a form for children, in this form i am trying to take the input as (date) type and calculate the difference by years and return a message or alert if the age was 18=< age <= 6, now I've tried many codes that I found in this site or other sites as : 1. javascript - Age calculation ( i tried : getTime() and other codes ) 2. https://www.w3resource.com/javascript-exercises/javascript-date-exercise-18.php and many had the same ideas, but all of them didn't work ..
here is the code :
</head>
<body>
<input type="date" id="userage" name="userage" onchange=""/>
<p id="k" ></p>
<script>
var a = document.getElementById('k').value ;
var b = Date.parse(a) ;
var c = new Date(b);
var d = c.getFullYear();
function useragefun(birthday){
var e = new Date();
var f = e.getFullYear();
var g = Math.floor(f - birthday);
if (g >= 18 || g <= 6 ){
document.getElementById('k').innerHTML = "You better sign in the adults form";
}else "" ;
}
</script>
</body>
// it could be this or an alert ..
to