javascriptjquerydatepickermindate

Disable past dates and enable only certain future dates in datepicker


I am attempting to use the jQuery datepicker, but wish to disable all past days and allow only future Thursdays. I can get it to allow Thursdays, but the minDate functionality I add doesn't work with it. This is my code:

<script>

jQuery(document).ready(function() {
    jQuery('#input_40_4').datepicker({
        beforeShowDay: function(date) { return [date.getDay() == 4, ""];}
   });
});

$(function () {
    $("#input_40_4'").datepicker({ minDate: 0 });
});

</script>

Can someone explain why these don't work together?


Solution

  • You can add more options to the datepicker by separating them by commas.

    $(document).ready(function() {
        $('#input_40_4').datepicker({
            beforeShowDay: function(date) { return [date.getDay() == 4, ""];},
            minDate : 0
            // you can add more options here as well, just seperate them by commas
       });
    });
    

    The reason why they didn't work in your question was because you would overwrite the options from the datepicker created in the function on line 10 with the options from the datepicker in the documentReady section.

    You were basically saying create a new datepicker with mindate:0, never mind create a new one with only Tuesdays.