0

this page offered sample code that would be ideal for a task I'm working on

Datepicker for web page that can allow only specific dates to be clicked

however, when I implement it, I get the following error: TypeError: Result of expression 'date.getMonths' [undefined] is not a function.

I'm testing using the same versions of jquery (1.4.4) and jquery ui on jquery ui's official site any help is greatly appreciated!

<!DOCTYPE html>
<html>
<head>
<base href="http://jqueryui.com/demos/datepicker/">
<title>TEST</title>
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
<script src="../../jquery-1.4.4.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">

<script>
$(function() {

dates_allowed = {'2/26/2011': 1,'4/2/2011': 1};
$.datepicker.setDefaults({minDate: "+0"});      
$.datepicker.setDefaults({maxDate: (new Date(2011, 3, 2))});

    $('#Date').datepicker({

    // called for every date before it is displayed
    beforeShowDay: function(date) {

        var date_str = [
            date.getFullYear(),
            date.getMonths() + 1,
            date.getDay()
        ].join('-');

        if (dates_allowed[date_str]) {
            return [true, 'good_date', 'This date is selectable'];
        } else {
            return [false, 'bad_date', 'This date is NOT selectable'];
        }
    }
});
});
</script>
</head>
<body>
<input type="text" id="Date">
</body>
</html>
Community
  • 1
  • 1
Dan
  • 3
  • 1

2 Answers2

0

That would be because it's .getMonth, singular.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

Most likely a typo.

use date.getMonth()

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317