I have input type=date
<input type="Date" name="todate" id="to">
in HTML
How to validate the date to systemdate
and before the current date it must be unavailable to click.I need to validate in Js
Please provide answers
That is my solution, first change the following html tag:
<input type="Date" name="todate" id="to">
To
<input type="Date" name="todate" id="to" onchange="checkit(this)">
The javascript function as follow:
function checkit(v)
{
var now=new Date();
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
now.setMilliseconds(0);
var userInput=new Date(v.value);
userInput.setHours(0);
userInput.setMinutes(0);
userInput.setSeconds(0);
userInput.setMilliseconds(0);
if (userInput.getTime()<now.getTime())
{
alert("User input date OLDER current date");
}
else
{
alert("User input date NOT older current date");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.