Link to home
Start Free TrialLog in
Avatar of SamJolly
SamJollyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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


Avatar of GwynforWeb
GwynforWeb
Flag of Canada image

Is the script for  Calendar.setup javascript?
ASKER CERTIFIED SOLUTION
Avatar of searlas
searlas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SamJolly

ASKER

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
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
SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am closing this now, as I think we have a lead on the solution.

Thanks to all,
Sam