Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JS Errors only with a DOCTYPE?

0 views
Skip to first unread message

Rick Brandt

unread,
Dec 17, 2005, 3:59:52 PM12/17/05
to
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


Ian

unread,
Dec 17, 2005, 5:22:00 PM12/17/05
to

Try the JavaScript console in Firefox, it will show the errors.

DOCTYPE does turn on compatibility mode in the browser.

Ian

Rick Brandt

unread,
Dec 17, 2005, 5:38:58 PM12/17/05
to

Yes I have done that. The mystery (to me) is that it highlights statements that
run just fine when DOCTYPE is not there. Most have to do with positioning and
retreiving values like .top and .left of various elements.

Are there validator sites for JS similar to those for HTML and CSS? If so I
guess I can run it through something like that to see what turns up.


Michael Winter

unread,
Dec 17, 2005, 7:08:19 PM12/17/05
to
On 17/12/2005 22:38, Rick Brandt wrote:

> Ian wrote:

[snip]

>> DOCTYPE does turn on compatibility mode in the browser.

If anything a document type declaration will make the browser more
strict, though that does force one to write code that will work in a
more compatible way.

[snip]

> The mystery (to me) is that it highlights statements that run just
> fine when DOCTYPE is not there. Most have to do with positioning and
> retreiving values like .top and .left of various elements.

Such as:

element.style.left = '24';

perhaps[1]? All CSS length values (which is what we are dealing with
here) /must/ have units unless the value is zero (0):

element.style.left = '24px';

> Are there validator sites for JS similar to those for HTML and CSS?

There are linters (like JSLint - http://www.jslint.com/), but otherwise
no. However, if one knows what constitutes valid CSS and a valid
document tree, then such a service shouldn't necessary.

[snip]

Mike


[1] The example won't generate an error, as such, but it will be
correctly ignored by a conforming browser for the reason
already given.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.

Thomas 'PointedEars' Lahn

unread,
Dec 17, 2005, 9:22:05 PM12/17/05
to
Ian wrote:

True.



> DOCTYPE does turn on compatibility mode in the browser.

False. A supposed-to-be HTML document without the DOCTYPE declaration
or with a DOCTYPE declaration with an unrecognized public identifier or
an unrecognized or missing system identifier triggers Quirks Mode/
Compatibility mode in both mentioned UAs. Everything else triggers
Standards Compliance Mode.

So if there is a change of behavior with the DOCTYPE delaration in
comparison to the same document without it, it is because of Standards
Compliance Mode with it (as the former is included and all its parts
are recognized and complete), not Quirks Mode.

<http://www.quirksmode.org/>


PointedEars

Ian

unread,
Dec 17, 2005, 10:45:27 PM12/17/05
to

>
>
>>DOCTYPE does turn on compatibility mode in the browser.
>
>
> False. A supposed-to-be HTML document without the DOCTYPE declaration
> or with a DOCTYPE declaration with an unrecognized public identifier or
> an unrecognized or missing system identifier triggers Quirks Mode/
> Compatibility mode in both mentioned UAs. Everything else triggers
> Standards Compliance Mode.
>
I should have said compliant rather than compatible, my mistake.

Ian

Rick Brandt

unread,
Dec 18, 2005, 9:02:21 AM12/18/05
to

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>


Dr John Stockton

unread,
Dec 19, 2005, 11:45:01 AM12/19/05
to
JRS: In article <NZdpf.34539$dO2....@newssvr29.news.prodigy.net>,
dated Sun, 18 Dec 2005 14:02:21 local, seen in
news:comp.lang.javascript, Rick Brandt <rickb...@hotmail.com> posted
:

> 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

You should be able to split dateFormat with a RegExp like
/^(\d+)([\/\.-])(\d+)(\2)(\d+)$/ and determine formatChar and the three
fields in one go.


> 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);

Instead of parseInt, you can probably use a unary + there & elsewhere -
see FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Rick Brandt

unread,
Dec 19, 2005, 8:09:02 PM12/19/05
to

Well thanks for that, but none of those lines have anything to do with the error
I'm seeing.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


VK

unread,
Dec 20, 2005, 6:57:55 AM12/20/05
to
Rick Brandt wrote:
> Well thanks for that, but none of those lines have anything to do with the error
> I'm seeing.

- "I'm seeing some errors"
- "This one?" - "That one?"
- "No, it is not the error I'm seeing".

It is not a "Chocolate" movie here - "Guess what chocolate I like the
best"
;-)

So instead of guessing game you should post at least *one* working
sample of an error appearing with DTD declaration.

Also note that not every single DTD declaration changes IE mode:
<http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/doctype.asp>

And here you can find a list of changes if you manage to switch IE into
strict mode:
<http://msdn.microsoft.com/library/en-us/dhtmltechcol/dndhtml/cssenhancements.asp>

Nothing to do with script as you can see. But CSS rule changes may
affect undirectly on your script.

Rick Brandt

unread,
Dec 20, 2005, 7:42:40 AM12/20/05
to
VK wrote:
> Rick Brandt wrote:
> > Well thanks for that, but none of those lines have anything to do
> > with the error I'm seeing.
>
> - "I'm seeing some errors"
> - "This one?" - "That one?"
> - "No, it is not the error I'm seeing".
>
> It is not a "Chocolate" movie here - "Guess what chocolate I like the
> best"
> ;-)
>
> So instead of guessing game you should post at least *one* working
> sample of an error appearing with DTD declaration.

I did post the code of the function that was raising the error, the exact line
where the error occurs, and the error message I am getting. I wasn't sure that
posting the entire js file would be appropriate. If you think that is necessary
though then let me know and I will do so. I currently do not have easy access
to a public site where I can provide a url to a (non-working) example, but could
try to set that up if necessary.

On a side note I searched the web and found another js popup calendar that I
liked almost as much as the one I first tried and it has the same problem. The
download consists of a js file and an html file. The sample html file has no
DOCTYPE and as soon as I added one everything went to hell. In IE the calendar
works but the location where it pops up is all messed up and in FF I get js
errors and no calendar at all.

If anyone can recommend a simple clean js calendar tool that actually works in
html compliance mode I would certainly appreciate it. Preferable one that uses
a div rather than a separate window.

Thanks again for any assistance.


VK

unread,
Dec 20, 2005, 7:47:35 AM12/20/05
to

Rick Brandt wrote:
> I did post the code of the function that was raising the error, the exact line
> where the error occurs, and the error message I am getting.

Sorry but it must be in some other thread not linked to this one.
In the current thread
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/882c9e2098f15b43/ece8cc4746ad43f3#ece8cc4746ad43f3>
I see only two of your post simply stating that you have some problems.
Could you provide a link to the original thread then?

Rick Brandt

unread,
Dec 20, 2005, 8:44:34 AM12/20/05
to

VK

unread,
Dec 20, 2005, 9:48:31 AM12/20/05
to

Rick Brandt wrote:
> Here is the post with the function code and error message.

> aTag = aTag.offsetParent; /*****ERROR ON THIS LINE*******/

Does it throw error right away (on the first loop) or somethere during
looping - put an alert() to check.

Somewhere on MSDN I've seen a *very very small* burk about how
offsetSomething is calculated in compatibility vs. strict mode.
Something like some margins(?) are included into calculation and some
not - depending on the mode. I put my life on I've seen but I was
stupid enough to not bookmark it right away. Now I cannot find it: was
it offsetWidth? innerHeight? some addon article?

Anyway: it cannot explain the fact that aTag or ctl stop becoming to be
objects.

Rick Brandt

unread,
Dec 20, 2005, 2:12:14 PM12/20/05
to
VK wrote:
> Rick Brandt wrote:
>> Here is the post with the function code and error message.
>
>> aTag = aTag.offsetParent; /*****ERROR ON THIS LINE*******/
>
> Does it throw error right away (on the first loop) or somethere during
> looping - put an alert() to check.[snip]

Okay I got it figured out. IE and Firefox were both throwing errors within
a couple lines of each other but they turned out to be completely unrelated
problems. IE was having problems with the following loop.

do {
aTag = aTag.offsetParent;


leftpos += aTag.offsetLeft;
toppos += aTag.offsetTop;
} while (aTag.tagName != 'BODY');

For some reason IE was looping two additional times compared to FF. This
error was corrected by changing to...

do {
aTag = aTag.offsetParent;


leftpos += aTag.offsetLeft;
toppos += aTag.offsetTop;

} while ((aTag.tagName != 'BODY') && (aTag.tagName != 'HTML'));

FF was complaining about several lines similar to...

crossobj.left = (fixedX == -1) ? ctl.offsetLeft + leftpos : fixedX;

This was corrected by adding a valid increment string to the end...

crossobj.left = ((fixedX == -1) ? ctl.offsetLeft + leftpos : fixedX) + "px";

The above actually should have been failures in all browser. IE just lets
you get away with using only numbers all the time while FF only allows it in
Quirks mode.

Thanks for the interest though.


Dr John Stockton

unread,
Dec 20, 2005, 5:42:37 PM12/20/05
to
JRS: In article <4%Spf.40326$tV6....@newssvr27.news.prodigy.net>,
dated Tue, 20 Dec 2005 12:42:40 local, seen in

news:comp.lang.javascript, Rick Brandt <rickb...@hotmail.com> posted
:

>If anyone can recommend a simple clean js calendar tool that actually works in
>html compliance mode I would certainly appreciate it. Preferable one that uses
>a div rather than a separate window.

It appears that you have not studied the newsgroup FAQ; see sig below.

There are many sorts of calendar, and it's not clear just what you want
- a month's calendar, a year's calendar, N months around a fixed date;
ISO compliant or FFF-compatible; with week numbers; etc. ?

Would this be a start?

2004 Aug
Mo Tu We Th Fr Sa Su
01
YYYY-MM 2004-08 Do 02 03 04 05 06 07 08
09 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

I don't know what you mean by "html compliance mode" : how about with
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> ?

Rick Brandt

unread,
Dec 20, 2005, 8:17:05 PM12/20/05
to
Dr John Stockton wrote:
> JRS: In article <4%Spf.40326$tV6....@newssvr27.news.prodigy.net>,
> dated Tue, 20 Dec 2005 12:42:40 local, seen in
> news:comp.lang.javascript, Rick Brandt <rickb...@hotmail.com>
> posted
> >
>
> > If anyone can recommend a simple clean js calendar tool that
> > actually works in html compliance mode I would certainly appreciate
> > it. Preferable one that uses a div rather than a separate window.
>
> It appears that you have not studied the newsgroup FAQ; see sig below.

Thanks for that. I found nothing relevant to my question there.

> There are many sorts of calendar, and it's not clear just what you
> want - a month's calendar, a year's calendar, N months around a fixed
> date; ISO compliant or FFF-compatible; with week numbers; etc. ?

My OP clearly stated what I was using and what problem I was having with it, but
thank you for your interest.


Dr John Stockton

unread,
Dec 21, 2005, 5:10:57 PM12/21/05
to
JRS: In article <l22qf.37206$q%.32820@newssvr12.news.prodigy.com>,
dated Wed, 21 Dec 2005 01:17:05 local, seen in

news:comp.lang.javascript, Rick Brandt <rickb...@hotmail.com> posted
:

>Dr John Stockton wrote:
>> JRS: In article <4%Spf.40326$tV6....@newssvr27.news.prodigy.net>,
>> dated Tue, 20 Dec 2005 12:42:40 local, seen in
>> news:comp.lang.javascript, Rick Brandt <rickb...@hotmail.com>
>> posted
>> >
>>
>> > If anyone can recommend a simple clean js calendar tool that
>> > actually works in html compliance mode I would certainly appreciate
>> > it. Preferable one that uses a div rather than a separate window.
>>
>> It appears that you have not studied the newsgroup FAQ; see sig below.
>
>Thanks for that. I found nothing relevant to my question there.

In that case you should read it more carefully. And, AISB, see below.

>> There are many sorts of calendar, and it's not clear just what you
>> want - a month's calendar, a year's calendar, N months around a fixed
>> date; ISO compliant or FFF-compatible; with week numbers; etc. ?
>
>My OP clearly stated what I was using and what problem I was having with it, but
>thank you for your interest.

The original post certainly does not describe what you want to produce;
it merely states that unspecified code gives unspecified errors in
unspecified browser versions when there is a DOCTYPE. But your fifth
post - the one to which I was responding - asks for a recommendation of
calendar code; and for that one needs to know what is necessary for a
calendar to fulfil your needs.

0 new messages