Click here to Skip to main content
Click here to Skip to main content
Go to top

jQueryUI DatePicker: Disable days in a week

, 25 Jul 2011
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.
 
He has years of successful records serving mid and large scale .NET applications. Have a wide range of experience working in domestic and international client environment. Expertise in different areas of software development life cycles and Software Architecture.
 
I am always looking for new information and value your feedback (especially where I got something wrong!).
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralNice i was looking for something like this :) Pinmembern.podbielski28-Jul-11 5:32 
GeneralRe: my pleasure. PinmemberMonjurul 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 | Mobile
Web02 | 2.8.140921.1 | Last Updated 25 Jul 2011
Article Copyright 2011 by Monjurul Habib
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid