Question

see there is a few post for this but tied but they don't seem to work.

var noWeekend = jQuery.datepicker.noWeekends(date);

currently my code does this and makes the weekends in active, but I would like it to do the opposite and make only the weekends active

Any idea how?

Was it helpful?

Solution

$("#txtDate").datepicker({ beforeShowDay: onlyWeekends});

function onlyWeekends(date) {
    var noWeekend = $.datepicker.noWeekends(date);
    if (noWeekend[0]) {
        return [false, ''];
    } else {
        return [true, ''];
    }
}

From the documentation: (http://api.jqueryui.com/datepicker/#option-beforeShowDay)

*beforeShowDay*

A function that takes a date as a parameter and must return an array with:

[0]: true/false indicating whether or not this date is selectable 
[1]: a CSS class name to add to the date's cell or "" for the default presentation 
[2]: an optional popup tooltip for this date

So you can return like this:

    if (noWeekend[0]) {
        return [false, 'hilite', 'oops, this is a weekday!'];
    } else {
        return [true, 'normal', 'ok to select'];
    }

OTHER TIPS

This tutorial appears to do exactly what you have described.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top