Reputation: 12998
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,""]}
Upvotes: 19
Views: 23060
Reputation: 1
beforeShowDay:function(date){
var day = date.getDay();
return [(day == 1 || day == 4),""];
}
Aakash Contractor (Asp.net Developer), Jain Jamatkhana pase, Ahmedabad
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 14873
try this
beforeShowDay: function(date)
{ return [(date.getDay() == 1 || date.getDay() == 4), ""]; }
Upvotes: 3
Reputation: 630419
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.
Upvotes: 30