Loading ...
Sorry, an error occurred while loading the content.

a note about calendar reference variable naming

Expand Messages
  • Matt Warden
    I ran into this today, and I see that this is mentioned somewhat in the docs, but I didn t take it the intended way when I originally read these lines. The
    Message 1 of 1 , Feb 24, 2006
    • 0 Attachment
      I ran into this today, and I see that this is mentioned somewhat in
      the docs, but I didn't take it the intended way when I originally read
      these lines. The lines are:

      "Create a calendar by instantiating Calendar with the ID of the
      element where component is to be inserted on the page."

      and:

      "Where:
      * id is the ID that should be assigned to the calendar component
      table element"

      In the example code, the calendar reference variable is named the same
      as the element ID passed in the function:

      "var cal1;
      function init() {
      cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");
      cal1.render();
      }"

      It is not simply a coincidence. In fact, it seems that you must name
      the element the same as your javascript variable, as the calendar
      component uses this to construct the "next month" and "previous month"
      functionality (and probably other things as well).

      Specifically, I had something like this:

      var cal;
      function init() {
      cal = new YAHOO.widget.Calendar("calAvailability","calContainer");
      cal.render();
      }

      I kept getting "calAvailability is undefined" errors when clicking the
      next month link (which is javascript:calAvailability.nextMonth()).

      (It took me a long time to figure this out, because I was thinking it
      cropped up when I moved things to an external stylesheet, and that
      maybe it had something to do with scoping.)

      It might be a good idea to make this clearer in the documentation.

      --
      Matt Warden
      Miami University
      Oxford, OH, USA
      http://mattwarden.com


      This email proudly and graciously contributes to entropy.
    Your message has been successfully submitted and would be delivered to recipients shortly.