Answers for "javascript disable date input dates"

1

html set input type date to disable previous dates

$(function(){
    var dtToday = new Date();
    
    var month = dtToday.getMonth() + 1;
    var day = dtToday.getDate();
    var year = dtToday.getFullYear();
    if(month < 10)
        month = '0' + month.toString();
    if(day < 10)
        day = '0' + day.toString();
    
    var maxDate = year + '-' + month + '-' + day;
    alert(maxDate);
    $('#txtDate').attr('min', maxDate);
});
Posted by: Guest on March-06-2020
0

disable few dates from calendar javascript

<head>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>

<body>
<input required class="datepicker" id="datepicker1" type="text" name="date" placeholder="Collection Date" autocomplete="off">  
</body>
  
<script>
// datepicker validation
$(document).ready(function() {

    var dates1 = ["20/05/2021", "21/05/2021", "22/05/2021"];

    function DisableDates1(date1) {
        var string = jQuery.datepicker.formatDate('dd/mm/yy', date1);
        return [dates1.indexOf(string) == -1];
    }

    jQuery("#datepicker1").datepicker({
        minDate: 2,
        dateFormat: "yy-mm-dd",
        changeMonth: true,
        numberOfMonths: 1,
        changeYear: true,

        beforeShowDay: DisableDates1,

        onClose: function(selectedDate, inst) {
            var minDate = new Date(Date.parse(selectedDate));
            minDate.setDate(minDate.getDate() + 2);
            jQuery("#datepicker2").datepicker("option", "minDate", minDate);
        }
    });
});
</script>
Posted by: Guest on May-29-2021

Code answers related to "javascript disable date input dates"

Browse Popular Code Answers by Language