6

I want to disable all days on this datepicker except the 1st and 15th of every month. I referenced this answered question, but I am only able to return one date. I'm a novice in javascript. jQuery UI DatePicker - Disable all days except last day of month

Any help would be great, thank you.

1
  • Ahah both answer are exactly the same, but you accepted the later one, weird :-)
    – Carlos2W
    Feb 10, 2016 at 20:52

2 Answers 2

14

This should do the trick:

$(function(){
    $("input").datepicker(
        {
        beforeShowDay: function (date) {

        if (date.getDate() == 15 || date.getDate() == 1) {
            return [true, ''];
        }
        return [false, ''];
       }
    });
});

​ Check out the link below for a working example!

http://jsfiddle.net/HM83u/

12

Seems like this would work

$('.selector').datepicker({
       beforeShowDay: function (date) {
       //getDate() returns the day (0-31)
       if (date.getDate() == 1 || date.getDate() == 15) {
           return [true, ''];
       }
       return [false, ''];
    }
});
1
  • Thanks you everyone, was so much easier than I was making it out to be.
    – Chris
    Aug 21, 2012 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.