Hi @Simflex,
You can change the jquery-ui library to make it easier.
Disabled dates (those outside the min/max) get the class ui-state-disabled added to them by the datepicker. Bind the click event to that class and set an alert.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="Stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$('#datepicker').datepicker({
minDate: -60,
maxDate: 0
});
$(document).on('click', '.ui-state-disabled', function () {
alert('Invalid date!!!Only select dates within the previous 60 days!!!')
})
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"/></p>
</body>
</html>
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.