Milligran
Milligran

Reputation: 3171

How to resolve Cannot read property 'timepicker' of undefined error

I am trying to implement the Jquery datetime picker on web page but keep getting the following error:

Uncaught TypeError: Cannot read property 'timepicker' of undefined

I downloaded the timepicker add on from here:

http://trentrichardson.com/examples/timepicker/#basic_examples

http://trentrichardson.com/examples/timepicker/jquery-ui-timepicker-addon.js

Here is the section of the code generating the error:

$.ui.timepicker = $.ui.timepicker || {};
if ($.ui.timepicker.version) {
    return;
}

On my web page I have the following:

<script type="text/javascript" src="/Scripts/jquery-lib/jquery-2.0.3.js"></script>

<script type="text/javascript"  src="/Content/bootstrap/js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript"  src="/Content/bootstrap/js/jquery.ui.datepicker.js"></script>
 <script type="text/javascript"  src="/Content/bootstrap/js/jquery-ui-sliderAccess.js"></script>

And script:

<script>
    $(function () {
        $("#datetimepicker").datepicker();
    });

Upvotes: 7

Views: 26635

Answers (2)

Vincent Vieira
Vincent Vieira

Reputation: 437

Uncaught TypeError: Cannot read property 'timepicker' of undefined means that

$.ui

is undefined. So, you probably have not included jQuery UI. Try to include it before any of your scripts (except jQuery itself).

Upvotes: 14

tymeJV
tymeJV

Reputation: 104775

You'll also have to import the jQuery lib to use jQuery plugins. Throw this script before the rest:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Upvotes: 0

Related Questions