Simon Kiely
Simon Kiely

Reputation: 6050

$("#datepicker").datepicker is not a function - JavaScript error

I am trying to link together fullcalendar and datepicker to form a nice calendar for myself but am running into the following error with me code :

Error message :

$("#datepicker").datepicker is not a function

Here is my code :

<link rel='stylesheet' type='text/css' href='../fullcalendar/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='../fullcalendar/fullcalendar.print.css' media='print' />
<link href="../scripts/jquery-ui-1.7.3.custom.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../Styles/dark-hive/jquery.ui.all.css">
<script src="../jquery/jquery-1.7.1.js"></script>
    <script type='text/javascript' src='../jquery/jquery-ui-1.8.17.custom.min.js'></script>
<script src="../jquery/ui/jquery.ui.core.js"></script>
<script src="../scripts/ui/jquery.ui.datepicker.js"></script>
<script type='text/javascript' src='../fullcalendar/fullcalendar.min.js'></script>

 <script type='text/javascript'>
$(function() {             
    $('#calendar').fullCalendar({ 
        theme: true, 
        header: { 
            left: '', 
            center: '', 
            right: '' 
        }, 
        defaultView: 'agendaDay', 
        editable: false, 
        events: "../fullcalendar/JSONcreator" 
    }); 
    $('#datepicker').datepicker({
        inline: true,
        onSelect: function(dateText, inst) {
            var d = new Date(dateText);
            $('#calendar').fullCalendar('gotoDate', d);
        }
    }); 
})
</script>

Also, is there any way of getting rid of some of the JQuery script calls at the top? There's sooo many, it seems so messy, but I am new to JQuery.

Upvotes: 2

Views: 22777

Answers (2)

Nick Beranek
Nick Beranek

Reputation: 2761

You can consolidate your jQuery as such:

$(document).ready(function() {
  // fullCalendar             
  $('#calendar').fullCalendar({ 
    theme: true, 
    header: { 
        left: '', 
        center: '', 
        right: '' 
    }, 
    defaultView: 'agendaDay', 
    editable: false, 
    events: "../fullcalendar/JSONcreator" 
  });

  // jQuery UI datepicker
  $('#datepicker').datepicker({
    inline: true,
    onSelect: function(dateText, inst) {
      var d = new Date(dateText);
      $('#calendar').fullCalendar('gotoDate', d);
    }
  }); 
});

You should only have one $(document).ready(function() {}); declaration. Keep it within your <script> tag at the bottom. It's the same as calling an event listener for load as such: window.addEventListener('load', function(){}, false);

Also, make sure that your scripts are loaded before you declare them.

Upvotes: 0

hohner
hohner

Reputation: 11588

You're loading fullcalendar.min.js before the page has loaded jquery-1.7.1.js, jquery.ui.core.js and jquery.ui.datepicker.js. Place it below them, otherwise it can't extend their functionality.

You can also reduce your code by placing your jQuery functions in one <script> tag rather than two:

<script type='text/javascript'>
$(function() {             
    $('#calendar').fullCalendar({ 
        theme: true, 
        header: { 
            left: '', 
            center: '', 
            right: '' 
        }, 
        defaultView: 'agendaDay', 
        editable: false, 
        events: "../fullcalendar/JSONcreator" 
    }); 
    $('#datepicker').datepicker({
        inline: true,
        onSelect: function(dateText, inst) {
            var d = new Date(dateText);
            $('#calendar').fullCalendar('gotoDate', d);
        }
    }); 
})
</script>

Upvotes: 6

Related Questions