Hi all,

I am working on an application.In which i am using calendar. In this page i am using calendar for Travel date and other for Return Date.

But i want that if i will select past date from calendar then is should give alert that we can select past dates.

so what is the procedure of doing this. Please help me.
Thanks,

Dani AI

Generated

For : two reliable ways to stop past dates are to disable them in the UI or to accept the pick but validate and reject with an alert. already pointed this out — below are compact, practical examples for modern pages and a quick client-side alert. Always enforce the same rule on the server; client checks can be bypassed.

HTML5 native date input (works in modern browsers). Set the min to today — build YYYY-MM-DD client-side to avoid timezone shifts:

<input id="travel" type="date" />

<script>
(function(){
  var d = new Date();
  var dd = String(d.getDate()).padStart(2,'0');
  var mm = String(d.getMonth()+1).padStart(2,'0');
  var today = d.getFullYear() + '-' + mm + '-' + dd;
  document.getElementById('travel').setAttribute('min', today);
})();
</script>

For jQuery UI Datepicker use minDate (simplest) or beforeShowDay to compare date-only values:

$("#travel").datepicker({
  minDate: 0,
  beforeShowDay: function(dt){
    var today = new Date();
    today.setHours(0,0,0,0);
    return [dt >= today, ""];
  }
});

If you prefer an immediate alert when a past date is picked (or as a fallback), compare the selected value to today and alert/clear the input. Finally, remember older browsers may ignore type="date", so include JS validation and server-side checks. For reference: input type=date docs and jQuery UI datepicker.

Recommended Answers

All 2 Replies

The best and simple one be:
Do not show past dates at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.