Click here to Skip to main content
11,705,212 members (53,505 online)
Click here to Skip to main content

jQueryUI DatePicker: Disable days in a week

, 25 Jul 2011 CPOL 16K 9
Rate this:
Please Sign up or sign in to vote.
How to disable days in a week in the jQueryUI DatePicker.

We already know how to use the jQuery UI DatePicker in ASP.NET. Here is a good reference.

I'm working with people who have a need for a DatePicker where users can only select Wednesday, Thursday, and Friday. And in addition, the user will not able to select any past date either. Following are the steps:

Make sure you add the following js and css files.

  • jquery-1.4.1.min.js
  • jquery.ui.core.js
  • jquery.ui.datepicker.js
  • jquery-ui-1.8.8.custom.css

Now paste the following code:

<script type="text/javascript">
    $(function () {
        var date = new Date();
        var currentMonth = date.getMonth(); // current month
        var currentDate = date.getDate(); // current date
        var currentYear = date.getFullYear(); //this year
        $("#<%= tbxRequestDeliveryDate.ClientID %>").datepicker({
            changeMonth: true, // this will allow users to chnage the month
            changeYear: true, // this will allow users to chnage the year
            minDate: new Date(currentYear, currentMonth, currentDate),
            beforeShowDay: function (date) {
                if (date.getDay() == 0 || date.getDay() == 1 || date.getDay() == 6) {
                    return [false, ''];
                } else {
                    return [true, ''];
                }
            }
        });
    });
</script>
<asp:TextBox ID="tbxRequestDeliveryDate" runat="server" CssClass="text"></asp:TextBox>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Monjurul Habib
Software Developer (Senior)
Bangladesh Bangladesh
A life-long-learner, maker and soft music fan. Likes building things to solve problems. Lives in Dhaka with wife and wonderful, smart kid and works as a Senior Software Engineer in applications architecture team.

Has years of successful records serving mid and large scale .NET applications in domestic and international client environment. Expertise in different areas of software development life cycles and Software Architecture.

Always looks for new information and value feedback (especially where got something wrong!).

You may also be interested in...

Comments and Discussions

 
GeneralNice i was looking for something like this :) Pin
n.podbielski28-Jul-11 5:32
membern.podbielski28-Jul-11 5:32 
GeneralRe: my pleasure. Pin
Monjurul Habib28-Jul-11 11:33
memberMonjurul Habib28-Jul-11 11:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 25 Jul 2011
Article Copyright 2011 by Monjurul Habib
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid