How To Disable Date only using JavaScript

In this tutorial we are going to use only javascript to disable date in HTML date input, and we will also  see the various example according to different situtations.

Determine the only javascript you are using. However, there are many datepicker libraries available, such as jQuery UI Datepicker, Bootstrap Datepicker, and Flatpicker. but in this tutorial, we are using vanilla JavaScript to achieve the goal.

We will see the below example in this tutorial:
  • Example 01: Disabled all past date
  • Example 02: Only enabled 3 months date from the current
  • Example 03: Disabled All Sunday from Callander
  • Example 04: Disabled all future date


Example 00: Disable past or future dates only using html attribute

if you do not want to use any JavaScript then you have min and max attributes in html data input.

with the help of these two attributes you can disable past or future dates or you can disable any specific date range.  here I am using PHP to get the current date. you can also provide a static value in the same format.

        
        <!-- disable past date --> 
<label for="date">Select a event Date:</label>
  <input type="date"  name="event" min="<?php echo date('Y-m-d'); ?>">

<!-- disable future date --> 
<label for="date">Select a DOB:</label>
  <input type="date"  name="dob" max="<?php echo date('Y-m-d'); ?>">
        
    

Example 01: Disabled all past date


Related Post

But if you have multiple  date filed with the same class then you can go with the below approach


Example 02: Only enabled 3 months date from the current


Example 03: Disabled All Sunday from Callander


Example 04: Disabled all future date


Leave a comment