2

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.

3
  • possible duplicate of stackoverflow.com/questions/1212696/… Commented Feb 27, 2012 at 16:35
  • 3
    shouldn't you load jquery before your fullcalendar plugin? Commented Feb 27, 2012 at 16:38
  • I think I have now done this (the code above reflects my change), the error is persisting, however. Thanks for the replies! Commented Feb 27, 2012 at 16:56

2 Answers 2

6

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer! I have now updated my code above, but the same problem is persisting!
Trying clearing your cache. Use Firebug or Chrome's Inspect Element tools to find out where your JavaScript is going wrong. If it's saying things like $("#datepicker").datepicker is not a function it generally means that your inline JavaScript function isn't hooking up to your external jQuery library
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.