19

I have the following code which only allows users to select Mondays from jquery datepicker.

I want to adapt this to be able to select mondays and thursdays.

Any ideas?

beforeShowDay: function(date){ return [date.getDay() == 1,""]}
Tom
  • 12,776
  • 48
  • 145
  • 240

4 Answers4

30

You can add an or (||) in there, like this:

beforeShowDay: function(date){ 
  var day = date.getDay(); 
  return [day == 1 || day == 4,""];
}

This only incurs the cost of .getDay() once per date shown, not that it's an expensive operation anyway, but no reason not to be efficient.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
3

try this

beforeShowDay: function(date)
{ return [(date.getDay() == 1 || date.getDay() == 4), ""]; }
Pramendra Gupta
  • 14,667
  • 4
  • 33
  • 34
0

It's better if you can add this: (disable after days and show Weekdays selected )

For example if you only want monday and friday remember ,0 sunday, 1 monday...... take out the weekdays you want block.

Works 100% on newest Jquery version

jQuery(function($){
$("#datepicker_es").datepicker({ minDate: 0,beforeShowDay: function(date)
{ return [(date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 || date.getDay() == 5 || date.getDay() == 6 || date.getDay() == 0), ""]; }}); 

it works for me..... and I hope works for all

GIMA
  • 1
0
      beforeShowDay:function(date){ 
               var day = date.getDay(); 
               return [(day == 1 || day == 4),""];
      }    

Aakash Contractor (Asp.net Developer), Jain Jamatkhana pase, Ahmedabad