Click here to Skip to main content
15,879,326 members
Articles / Web Development / ASP.NET
Tip/Trick

jQueryUI DatePicker: Disable days in a week

Rate me:
Please Sign up or sign in to vote.
4.87/5 (8 votes)
25 Jul 2011CPOL 33.3K   9   2
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:


HTML
<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)


Written By
Software Developer (Senior)
Singapore Singapore
A life-long-learner, maker and soft music fan. Likes building things to solve problems. 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 technology and loves to get hands dirty Smile | :)

Comments and Discussions

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

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

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