Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The datepicker is not working in this example.

Error code:
JavaScript runtime error: Object doesn't support property or method 'datepicker'

Code:
XML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        /* create an array of days which need to be disabled */
        var disabledDays = ["2-21-2010","2-24-2010","2-27-2010","2-28-2010","3-3-2010","3-17-2010","4-2-2010","4-3-2010","4-4-2010","4-5-2010"];

        /* utility functions */
        function nationalDays(date) {
            var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
            //console.log('Checking (raw): ' + m + '-' + d + '-' + y);
            for (i = 0; i < disabledDays.length; i++) {
                if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > date) {
                    //console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
                    return [false];
                }
            }
            //console.log('good:  ' + (m+1) + '-' + d + '-' + y);
            return [true];
        }
        function noWeekendsOrHolidays(date) {
            var noWeekend = jQuery.datepicker.noWeekends(date);
            return noWeekend[0] ? nationalDays(date) : noWeekend;
        }

        /* create datepicker */
        jQuery(document).ready(function() {
            jQuery("#<%=TextBox1.ClientID%>").datepicker({
                minDate: new Date(1900, 0, 1),
                maxDate: new Date(2100, 12, 31),
                dateFormat: 'DD, MM, d, yy',
                constrainInput: true,
                beforeShowDay: noWeekendsOrHolidays
            });
        });
    </script>
Posted

1 solution

Who told you jQuery has this member? It doesn't. You did not even include proper JavaScript UI library, "jquery-ui.js", only included the core jQuery via "jquery.min.js".

The usage of jQuery datepicker is clearly explained here, with a code sample: https://jqueryui.com/datepicker[^].

—SA
 
Share this answer
 
Comments
Maciej Los 1-Jun-15 14:56pm    
5ed!
Sergey Alexandrovich Kryukov 1-Jun-15 14:59pm    
Thank you, Maciej.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900