20

This question is already asked many times but none of them worked for me. I am trying to use this date picker in a JSP file. This is my script

<head>
<title>My Home</title>
<link rel="stylesheet" type="text/css"
href="../resource/css/page-style.css" />
<link rel="stylesheet" type="text/css"
href="../resource/css/jQuery-ui.css" />
<script src="../resource/js/jquery-1.9.1.js"></script>
<script src="../resource/js/jquery-ui.js"></script>
<script type="text/javascript" src="../resource/js/form-elements.js"></script>

<script type="text/javascript">
$("document").ready(function() {
    $("#shortcuts").load("shortcut.html");
    $("#datepicker").datepicker();
    alert('jQuery is working');
});
</script>
</head>

The shortcut file is loading perfectly, alert is also showing. I get error message as TypeError: $(...).datepicker is not a function. I am not facing this problem if I run this script in a html file placed in my desktop, when I copy the come code to my IDE and run it I get this error in my console. Please suggest me what can I do? I know this question is asked several times I have checked every answer this is the only link having close match to my prob but didn't work for me.

Community
  • 1
  • 1
NewUser
  • 3,729
  • 10
  • 57
  • 79

3 Answers3

39

The problem is with your imported files.I think you have not placed them properly.

Try to import these files

 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

It is working for me.

see here for more information

Community
  • 1
  • 1
PSR
  • 39,804
  • 41
  • 111
  • 151
  • Replacing the relative source to the url works file. But, why? any guess? – NewUser Mar 15 '13 at 07:04
  • copy the same files now into your folder.then try – PSR Mar 15 '13 at 07:05
  • @Dibya whatever the files you are using previously they may not correct.otherwise the path what you gave is not correct – PSR Mar 15 '13 at 07:07
  • @Dibya are you copying those files – PSR Mar 15 '13 at 07:08
  • I was trying, I can refer to my jquery-ui.js file correctly but the reference file is not working locally. I have this code now: `` `` and this is working. :( – NewUser Mar 15 '13 at 07:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26220/discussion-between-dibya-and-psr) – NewUser Mar 15 '13 at 07:16
20

Double check that there are no JQuery references after your JQuery-ui reference.

I had an extra JQuery reference that came after my JQuery-ui reference and lost an hour chasing the problem. That will cause the datepicker not found error.

Mark Kadlec
  • 8,036
  • 17
  • 60
  • 96
1

This is something to do with the import files. I also faced the same scenario and following imports helped me to overcome the following issue "datepicker is not a function".

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51