Macky Miro Macky Miro - 1 month ago 4
jQuery Question

Disabled the past dates in datepicker and selected only "monday"

I have this datepicker in my input textbox it runs well the datepicker and the selected only too. My problem is want to disabled the past dates and only the future selected day "Monday" only . Here is my code below

<input type='text' name='datepicker' id='datepicker' placeholder='Date:' class='form-control'>


$(function() {
$("#datepicker").datepicker({
beforeShowDay: function (date) {
//getDate() returns the day (0-31)
if (date.getDay() == 1 ) {
return [true, ''];
}
return [false, ''];
}
});
});


What happen to my code is that the monday is selected but the past dates is not disabled. Can someone help me figured this thing out on how can i disabled the past dates?TIA

Answer

Try this... Pass mindate=0;

$(function() {
    $("#datepicker").datepicker({
        minDate:0,
        beforeShowDay: function (date) {
            //getDate() returns the day (0-31)
            if (date.getDay() == 1 ) {
                return [true, ''];
            }
            return [false, ''];
        }
    });
});
Comments