Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $.datepicker is undefined

my javascript has code, for one of the pages on my website:

$('#nmdt1').datetimepicker({
        dateFormat: $.datepicker.ATOM,
        minDate: nmsdt,
                  ...
                  ...

this runs fine, when the page on which id="nmdt1" is loaded. And I load the related datetimepicker js library (module) only on when i load that page. so far so good.

but when i load any other pages on my websit i get this error: from the line number where dateformat is defined.

EDIT: here is the correct error for firebug log:

TypeError: $.datepicker is undefined
http://myswbsite/jscript/myjsscript.js
Line 569

line 569 is:

dateFormat: $.datepicker.ATOM,

and yes, this error only comes on page where I am not loading the related js code (jquery-ui-timepicker-addon.js). The reason I am not loading this js on every page is, i need it on only one page.

MORE DETAILS:

in HTML header following lib loads (in seq)

<head>
    <script src="/jscript/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="/jscript/myjsscript.js" type="text/javascript"></script>
...
...
    <script type="text/javascript">
    jQuery(document).ready(function(){
        var mid = "[% mid %]";
        alert('mid='+mid);
        $(".bvmainmenu #"+mid).css({"background":"url(/images/current-bg.gif) top left repeat-x", "color":"#ffffff"});
    });
    </script>
</head>

this last javascript code you see above (bottom of header) does not run each time when the jquery-ui-timepicker-addon.js lib is not loaded (and you see that err in firebug - i can live with error, but why this last code is not running, i am not sure). I am not able to understand why this routine wont run just because i did not load one 'add-on' library

the page which runs everything correctly loads following js scripts in BODY

<script src="/jscript/jquery-ui-1.8.21.custom.min.js" type="text/javascript"></script>
<script src="/jscript/jquery-ui-timepicker-addon.js" type="text/javascript"></script>

on this page the last javascript code you see in header also loads and displays the alert!

I am having tough time to figure this.

like image 705
rajeev Avatar asked Dec 06 '22 12:12

rajeev


2 Answers

Have you included jQuery UI in your application.

<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.22/jquery-ui.min.js"></script>
like image 193
Arun P Johny Avatar answered Dec 11 '22 09:12

Arun P Johny


Make sure that $ is your jquery shortcut identifier. Check the usage of

var $J = jQuery.noConflict();

In that case try to use $J.datepicker

like image 39
sree Avatar answered Dec 11 '22 11:12

sree