Wednesday, 14 August 2013

Datepicker disable specific weekdays

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css"
        type="text/css" media="all" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            // 0 = monday, 1 = tuesday, 2 = wednesday, 3 = thursday,
            // 4=friday, 5 = saturday, 6=sunday

            var daysToDisable = [2, 4, 5];

            $('#txtDate').datepicker({
                beforeShowDay: disableSpecificWeekDays
            });

            function disableSpecificWeekDays(date) {
                var day = date.getDay();
                for (i = 0; i < daysToDisable.length; i++) {
                    if ($.inArray(day, daysToDisable) != -1) {
                        return [false];
                    }
                }
                return [true];
            }
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input type="text" ID="txtDate" />
    </form>
</body>
</html>

OUTPUT



No comments:

Post a Comment