3

I am trying to use date picker of jquery in mvc4.

It was giving me error:

Uncaught TypeError: undefined is not a function

My jQuery function is like:

$(document).ready(function () {
    $('#dpFrom').datepicker();
});

html part is like:

 <input type="text" id="dpFrom"  />

I refered :

Uncaught TypeError: undefined is not a function while using jQuery UI

And included :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

So total javascript became:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>  
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('#dpFrom').datepicker();

    });
</script>

Still its giving me error.

Please help...

Community
  • 1
  • 1
Shital Kadam
  • 238
  • 2
  • 5
  • 14
  • Can you reproduce your problem in a fiddle ? – Denys Séguret Nov 03 '14 at 10:38
  • working fine for me, with the data you've provided. – Ravi Nov 03 '14 at 10:40
  • 1
    I think that you have a duplicate jQuery reference. Could you open a "View Source" on your web browser and enumerate your jQuery references? It is a common error and easily missed. Maybe a bundle definition or your layout and content pages have the same reference. – Chris Nov 03 '14 at 10:50
  • @Chris -yup. there was a duplicate jQuery reference.I just comment out one. and its working fine. – Shital Kadam Nov 03 '14 at 11:39

3 Answers3

13

I think that you have a duplicate jQuery reference. Could you open a "View Source" on your web browser and enumerate your jQuery references? It is a common error and easily missed. Maybe a bundle definition or your layout and content pages have the same reference.

Chris
  • 5,040
  • 3
  • 20
  • 24
1

The path should be https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js not //ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js in both referencing script and css tags

Mohit
  • 2,189
  • 4
  • 22
  • 40
0
<script type="text/javascript">
    $( "#datepicker" ).datepicker();      
</script>

I tried this one, when i erase the function().

lothux1987
  • 140
  • 2
  • 14