0

In my Django project I'm trying to add a datepicker using jQuery. When I load page in a browser the console gives me an error:

Uncaught TypeError: $(...).datepicker is not a function

I tried the same AJAX code in a simple HTML page and it works fine there. Why is this datepicker() function not loading in Django from source location?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <title>Hello, world!</title>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
  <script>
    $(function() {
      $("#datepicker").datepicker();
    });
  </script>
  <p>Date: <input type="text" id="datepicker"></p>
  {% block contents %} {% endblock %}
</body>
</html>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
sanghmitra
  • 21
  • 2
  • 9
  • I placed your code in an executable snippet where it works fine. Are there any other errors in the console? Perhaps about the script references leading to 404 errors, or conflicts? – Rory McCrossan Nov 07 '19 at 14:15
  • here is the solution: https://stackoverflow.com/questions/36207203/uncaught-typeerror-datepicker-is-not-a-functionanonymous-function – Yazan M. Al-Horani Nov 07 '19 at 14:28
  • your solution helped me to find the mistake. Thanks :) @YazanM.Al-Horani – sanghmitra Nov 08 '19 at 05:04

1 Answers1

0

Let's click to the link click download the datepicker package and import any of js file to your templates

This will solve your problem

Nj Nafir
  • 570
  • 3
  • 13