I have an HTML page and I have a field called Rating Date. I don't want the user to enter a future date. I need a javascript code to allow only past or present date. Unfortunately, I don't really know JS; any tips will be greatly appreciated.
something like this (very simple concept - should probably be made more robust with validations, etc...
Code:
function noFutureDate(d) {
var today = new Date();
var user_date = new Date(d.value);
if (d.value.length > 0) {
if (user_date > today) {
alert("date can't be a future date!");
d.value = "";
d.focus();
}
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.