Can Datepicker get dateMin from span?
I have this span:
- <div id="Availability" style="display: hidden">8</div>
Then I have a giant chunk of script for the jQuery ui datepicker:
- //datepicker
var natDays = [
[1, 1, 'New Year'], //2014
[1, 20, 'Martin Luther King'], //2014
[2, 17, 'Washingtons Birthday'], //2014
[5, 26, 'Memorial Day'], //2014
[7, 4, 'Independence Day'], //2014
[9, 1, 'Labour Day'], //2014
[10, 13, 'Columbus Day'], //2014
[11, 11, 'Veterans Day'], //2014
[11, 27, 'Thanksgiving Day'], //2014
[12, 25, 'Christmas'] //2014
];
// dateMin is the minimum delivery date
var dateMin = new Date();
dateMin.setDate(dateMin.getDate() + (dateMin.getHours() >= 13 ? 1 : 0));
function AddBusinessDays(curdate, weekDaysToAdd) {
var offset = (weekDaysToAdd > 0 ? +1 : -1);
weekDaysToAdd = Math.abs(weekDaysToAdd);
var date = new Date(curdate.getTime());
while (weekDaysToAdd > 0) {
date.setDate(date.getDate() + offset);
//check if current day is business day
if (noWeekendsOrHolidays(date)[0]) {
weekDaysToAdd--;
}
}
return date;
}
function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
return (noWeekend[0] ? nationalDays(date) : noWeekend);
}
function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];
}
function setDeliveryDate(date) {
$('#datepicker3').text($.datepicker.formatDate('DD, MM d, yy', AddBusinessDays(date, -2)));
$('#datepicker2').text($.datepicker.formatDate('DD, MM d, yy', AddBusinessDays(date, -3)));
$('#local-delivery-date').text($.datepicker.formatDate('DD, MM d, yy', AddBusinessDays(date, -3)));
}
$('#delivery-date').text($.datepicker.formatDate('DD, MM d, yy', AddBusinessDays(dateMin, 5)));
setDeliveryDate(AddBusinessDays(dateMin, 5));
$.datepicker.setDefaults({
beforeShowDay: noWeekendsOrHolidays,
showOn: 'both',
firstDay: 0,
dateFormat: 'mm/dd/yy',
changeFirstDay: false,
showButtonPanel: true
});
// use datepicker to choose a different delivery date
$('#datepicker').datepicker({
minDate: AddBusinessDays(dateMin, 5),
onSelect: function(datestring) {
setDeliveryDate($(this).datepicker('getDate'));
}
});
$('#LocalDate').datepicker({
minDate: AddBusinessDays(dateMin, 2)
});
Wondering if it's possible to get the number within my span, in this case 8, and have the datepicker use that as the minDate here (rather than the 5):
- $('#datepicker').datepicker({
minDate: AddBusinessDays(dateMin, 5),
Thanks very much in advance, all help is appreciated!
Susan