Rick Brandt wrote:
We are using a JS popup calendar in our pages and find that we get
various JS errors whenever we call the code from an HTML page that
includes a DOCTYPE. The specific type doesn't seem to matter. As
long as there is no DOCTYPE then everything works fine (IE and FF).
I don't have the specific script or errors handy, but I was wondering
if there are some general things I can look for. Is the JS page just
using some deprecated methods that are not flagged unless a DOCTYPE
pushes the browser into a newer compatibility mode?
TIA
After further investigation it appears that the use of offsetParent is involved
and I did find this on the web that indicates a difference between compliance
mode and Quirks mode...
<ref>
offsetParent returns a reference to the object which is the closest (nearest in
the containment hierarchy) positioned containing element. If the element is
non-positioned, the root element (html in standards compliant mode; body in
quirks rendering mode) is the offsetParent.
</ref>
So I am guessing that in compliance mode the js is doing something with
offsetParent that is illegal when it refers to html instead of body.
I also found this reference which sounds a bit more ominous...
<ref>
The offsetParent, offsetLeft and offsetTop properties are supported by Internet
Explorer 4+ and NS6+ and are not part of the W3C DOM specification.
</ref>
Here is one of the functions that throws the error. The error "Object Required"
occurs at the line...
aTag = aTag.offsetParent;
<code>
function popUpCalendar(ctl, ctl2, format) {
var leftpos = 0;
var toppos = 0;
if (bPageLoaded) {
if (crossobj.visibility == 'hidden') {
ctlToPlaceValue = ctl2;
dateFormat = format;
formatChar = ' ';
aFormat = dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = '/';
aFormat = dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = '.';
aFormat = dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = '-';
aFormat = dateFormat.split(formatChar);
if (aFormat.length < 3) {
formatChar = ''; // invalid date format
}
}
}
}
tokensChanged = 0;
if (formatChar != "") {
aData = ctl2.value.split(formatChar); // use user's date
for (i=0; i<3; i++) {
if ((aFormat[i] == "d") || (aFormat[i] == "dd")) {
dateSelected = parseInt(aData[i], 10);
tokensChanged++;
} else if ((aFormat[i] == "m") || (aFormat[i] == "mm")) {
monthSelected = parseInt(aData[i], 10) - 1;
tokensChanged++;
} else if (aFormat[i] == "yyyy") {
yearSelected = parseInt(aData[i], 10);
tokensChanged++;
} else if (aFormat[i] == "mmm") {
for (j=0; j<12; j++) {
if (aData[i] == monthName[language][j]) {
monthSelected=j;
tokensChanged++;
}
}
} else if (aFormat[i] == "mmmm") {
for (j=0; j<12; j++) {
if (aData[i] == monthName2[language][j]) {
monthSelected = j;
tokensChanged++;
}
}
}
}
}
if ((tokensChanged != 3) || isNaN(dateSelected) || isNaN(monthSelected) ||
isNaN(yearSelected)) {
dateSelected = dateNow;
monthSelected = monthNow;
yearSelected = yearNow;
}
odateSelected = dateSelected;
omonthSelected = monthSelected;
oyearSelected = yearSelected;
aTag = ctl;
do {
aTag = aTag.offsetParent; /*****ERROR ON THIS LINE*******/
leftpos += aTag.offsetLeft;
toppos += aTag.offsetTop;
} while (aTag.tagName != 'BODY');
crossobj.left = (fixedX == -1) ? ctl.offsetLeft + leftpos : fixedX;
crossobj.top = (fixedY == -1) ? ctl.offsetTop + toppos + ctl.offsetHeight + 2
: fixedY;
constructCalendar (1, monthSelected, yearSelected);
crossobj.visibility = (dom||ie) ? "visible" : "show";
hideElement('SELECT', document.getElementById('calendar'));
hideElement('APPLET', document.getElementById('calendar'));
bShow = true;
} else {
hideCalendar();
if (ctlNow!=ctl) popUpCalendar(ctl, ctl2, format);
}
ctlNow = ctl;
}
}
</code>