Issue
let Year = document.getElementById('year').value;
let Month = document.getElementById('month').value;
let date = document.getElementById("day").value;
if(typeof Year !== "number" || typeof Month !== "number" || typeof date !== "number"){
alert("Invalid Date ");
}
I was expecting no alert as I input numeric values, but it was still displaying the alert message in the condition.
Solution
The value of Input is always string.
So, you can do like below.
let Year =document.getElementById('year').value;
let Month =document.getElementById('month').value;
let date =document.getElementById("day").value;
if(isNaN(Year+Month+date) ){
alert("Invalid Date ");
}
you need more validation like date > 0
... but my code is enough as your code now.
I think my answer can help you.
Answered By - J.Porter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.