Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 897
  • Last Modified:

Object 'is undefined'.... intermittent error...need a clue please.....

Hi All,

I use a great little Javascript Calendar component called JSCalendar. We have this running with 100s of users without a problem. On three machines we have encountered

'Calendar is undefined' which is really strange.

The first occurrence was with a desktop running IE5, and when updated to IE6 the issue went away.

We now have 2 laptops with the same problem, different site. These laptops are running IE6.0.29 on Windows 2000, patched to date, and apparently have the same config as all the desktops in the same company which all work fine... what????

So for the code.

In the <head> section I reference the Calendar code files.

<link href="../../../Js/Other/JSCalendar/calendar-theme.css" rel="stylesheet" type="text/css"/>      
<script type="text/javascript" src="../../../Js/Other/JSCalendar/calendar.js"></script>
<script type="text/javascript" src="../../../Js/Other/JSCalendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="../../../Js/Other/JSCalendar/calendar-setup.js"></script>

In the body I have a textbox with an arrow image to the right of it which when clicked brings up the calendar. When you click on the calendar on the relevant date, the value goes into the textbox. The calendar is a CSS layer so no need for a popup.

This is the calling code in the <body>

<div id="FromDateValue">
<input id="tbFromDate" name="FromDate" style="width:157px;height:19px" type="text" class="REM_FormTextboxGo" value="01/01/2004" size="16" maxlength="20" onBlur="blnIsDirty=true;"/>
</div>
<div id="FromDateGo">
   <a id="HlImgFromDateGo" href="#">
      <img id="ImgFromDateGo" onClick="blnIsDirty=true;" src="../../../img/ddlb.gif" alt="Click Here to Pick up the date" border="0"/>
   </a>

   <script type="text/javascript">
    Calendar.setup({
        inputField     :    "tbFromDate",     // id of the input field
        ifFormat       :    "%d/%m/%Y",      // format of the input field
        daFormat       :    "%d/%m/%Y",      // format of the input field            
        button         :    "HlImgFromDateGo",  // trigger for the calendar (button ID)
        align          :    "Bl",           // alignment (defaults to "Bl")
        singleClick    :    true
    });
   </script>

</div>

I appreciate that you may be unfamiliar with this component, but I thought someone may have an idea of why this intermittent JS error would occur, expecially when 98% of the users are fine, so nothing intrinsically wrong with the app.

Any ideas would be hugely appreciated,

Sam


0
SamJolly
Asked:
SamJolly
2 Solutions
 
GwynforWebCommented:
Is the script for  Calendar.setup javascript?
0
 
searlasCommented:
Probable cause is the machines failing to load the javascript.  The browser *should* wait till all those scripts are loaded before processing the rest of the page, but for a number of reasons this may not be happening (network/proxy issues; even a different subnet in an office might be enough to throw this out.)

Instead of calling the Calendar.setup inline as you are now, attach it as an 'onload' event to ensure the JS files it depends on have already loaded.

One question: does this 'Calendar is undefined' error occur everytime these few users load the page, or just the 1st time?  If it's everytime, it's likely the users concerned aren't allowing their browsers to cache anything.
0
 
SamJollyAuthor Commented:
Yes it is,

There is a fair amount of code. I include some useful parts of it.

It starts like this:

Calendar.setup = function (params) {
      function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };

      param_default("inputField",     null);
      param_default("displayArea",    null);
      param_default("button",         null);
      param_default("eventName",      "click");
      param_default("ifFormat",       "%Y/%m/%d");
      param_default("daFormat",       "%Y/%m/%d");
      param_default("singleClick",    true);
      param_default("disableFunc",    null);
      param_default("dateStatusFunc", params["disableFunc"]);      // takes precedence if both are defined
      param_default("mondayFirst",    true);
      param_default("align",          "Bl");
      param_default("range",          [1900, 2999]);
      param_default("weekNumbers",    true);
      param_default("flat",           null);
      param_default("flatCallback",   null);
      param_default("onSelect",       null);
      param_default("onClose",        null);
      param_default("onUpdate",       null);
      param_default("date",           null);
      param_default("showsTime",      false);
      param_default("timeFormat",     "24");


and laterly there seems to be some instantiation:

      var triggerEl = params.button || params.displayArea || params.inputField;
      triggerEl["on" + params.eventName] = function() {
            var dateEl = params.inputField || params.displayArea;
            var dateFmt = params.inputField ? params.ifFormat : params.daFormat;
            var mustCreate = false;
            var cal = window.calendar;
            if (!window.calendar) {
                  window.calendar = cal = new Calendar(params.mondayFirst,
                                               params.date,
                                               params.onSelect || onSelect,
                                               params.onClose || function(cal) { cal.hide(); });
                  cal.showsTime = params.showsTime;
                  cal.time24 = (params.timeFormat == "24");
                  cal.weekNumbers = params.weekNumbers;
                  mustCreate = true;
            } else {
                  cal.hide();
            }
            cal.setRange(params.range[0], params.range[1]);
            cal.params = params;
            cal.setDateStatusHandler(params.dateStatusFunc);
            cal.setDateFormat(dateFmt);
            if (mustCreate)
                  cal.create();
            cal.parseDate(dateEl.value || dateEl.innerHTML);
            cal.refresh();
            cal.showAtElement(params.displayArea || params.inputField, params.align);
            return false;
      };

I hope this helps.

really apreciate your input,

Sam
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
SamJollyAuthor Commented:
Searlas,

Just read your comments. Very interesting...

>>One question: does this 'Calendar is undefined' error occur everytime these few users load the page, or just the 1st time?  If it's everytime, it's likely the users concerned aren't allowing their browsers to cache anything.

Yes, it happens all the time. How can I reproduce this non caching behaviour - is there an IE setting that I can change?

I will comme bck to the onLoad solution after I have checked the Caching..

Thanks,

Sam
0
 
ZvonkoSystems architectCommented:
The question from searlas was: why it is not possible for you to call the Calendar.setup() from <body onLoad>
The creators of that calendar script do that in their pages.

My proposla is to do it in <body onLoad="Calender.setup()"> only for test on one of the failing workstations.
If it works with onLoad, then you know that you have a timing problem.

0
 
SamJollyAuthor Commented:
I am closing this now, as I think we have a lead on the solution.

Thanks to all,
Sam
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now