Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I want to create datepicker, somehow when i debug i often get this annoying error as "
Index:187 Uncaught TypeError: $(...).datepicker is not a function
    at HTMLDocument.<anonymous> (Index:187)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at Function.ready (jquery.min.js:2)
    at HTMLDocument.K (jquery.min.js:2)
". Have a look at my libraries and yet Datepicker is already installed on Nuget command.

What I have tried:

// Libraries imported on View.cshtml
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css">


//
<div class="form-group">
                <label asp-for="Date_Created" class="control-label"></label>
                <input asp-for="Date_Created" id="datepicker" type="text" class="form-control" value="@DateTime.Now.ToString("yyyy-MM-ddThh:mm")" />
                <span asp-validation-for="Date_Created" class="text-danger"></span>
            </div>
            <script>
                $(document).ready(function () {
                    $(".datepicker").datepicker({
                        dateFormat: "dd-mm-yy",
                        changemonth: true,
                        changeyear: true
                    });
                });
            </script>


//___Layout.cshtml
 @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    
</head>
<body>
    <!---Adding a picture for customization-->
   
    <div class="container body-content">
        @RenderBody()
        <hr />

    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
Posted
Updated 9-Nov-21 2:20am

1 solution

In the browser, check the developer tools window and see if the bootstrap-datetimepicker.min.js file is actually being found and loaded.
 
Share this answer
 
Comments
Gcobani Mkontwana 2021 9-Nov-21 8:52am    
@realJSOP its complain it does not. what could i be missing based on the libraries used and nuget install on my VS IDE
#realJSOP 9-Nov-21 8:55am    
I have no idea why it wouldn't be found. I just pasted the url for it into my browser, and it came up fine. Personally, I would *never* load a css or javascript file from a remote location, because if that remote location goes away or goes down, so does *my* web site. Beyond that, DNS attacks on cloudflare happen with all too much regularity.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900