Skip to content

Instantly share code, notes, and snippets.

@albertpak
Created August 8, 2013 21:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertpak/6188772 to your computer and use it in GitHub Desktop.
Save albertpak/6188772 to your computer and use it in GitHub Desktop.
How to disable (or enable - reverse true/false in nonPartyDays function ) days of the week in jQuery UI Datepicker based on which days are checked off.
<table id="daysoftheweek">
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><input type="checkbox" value="0" class="availableDays" /></td>
<td><input type="checkbox" value="1" class="availableDays" /></td>
<td><input type="checkbox" value="2" class="availableDays" /></td>
<td><input type="checkbox" value="3" class="availableDays" /></td>
<td><input type="checkbox" value="4" class="availableDays" /></td>
<td><input type="checkbox" value="5" class="availableDays" /></td>
<td><input type="checkbox" value="6" class="availableDays" /></td>
</tr>
</table>
<input type="text" name="eventDay" id="eventDay" />
var needToSeeDaysOfWeek = new Array();
$(function() {
$("#eventDay").datepicker({
showOn: "button",
buttonImage: "https://cdn1.iconfinder.com/data/icons/icojoy/noshadow/standart/png/24x24/001_44.png",
buttonImageOnly: false,
dateFormat: 'mm/dd/yy',
minDate: 0,
beforeShowDay: nonPartyDays
});
$("#daysoftheweek input:checkbox").change(function(){
var v=$(this).attr("value")*1;
var f=$.inArray(v,needToSeeDaysOfWeek);
if($(this).is(":checked")){
if(f<0){
needToSeeDaysOfWeek.push(v);
}
}else{
if(f>=0){
needToSeeDaysOfWeek.splice(f,1);
}
}
});
});
function nonPartyDays(date){
var day = date.getDay();
for(var i=0;i<needToSeeDaysOfWeek.length;i++){
if(day==needToSeeDaysOfWeek[i]){
return [false];
}
}
return [true];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment