468,167 Members | 1,931 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,167 developers. It's quick & easy.

JS Errors only with a DOCTYPE?

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
Dec 17 '05 #1
17 1830
Ian
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?


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

DOCTYPE does turn on compatibility mode in the browser.

Ian
Dec 17 '05 #2
Ian wrote:
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?


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

DOCTYPE does turn on compatibility mode in the browser.

Ian


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.
Dec 17 '05 #3
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.
Dec 18 '05 #4
Ian wrote:
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?
Try the JavaScript console in Firefox, it will show the errors.


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
Dec 18 '05 #5
Ian

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
Dec 18 '05 #6
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>
Dec 18 '05 #7
JRS: In article <NZ*******************@newssvr29.news.prodigy.net> ,
dated Sun, 18 Dec 2005 14:02:21 local, seen in
news:comp.lang.javascript, Rick Brandt <ri*********@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.
Dec 19 '05 #8
Dr John Stockton wrote:
JRS: In article <NZ*******************@newssvr29.news.prodigy.net> ,
dated Sun, 18 Dec 2005 14:02:21 local, seen in
news:comp.lang.javascript, Rick Brandt <ri*********@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.


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
Dec 20 '05 #9
VK
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.

Dec 20 '05 #10
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.
Dec 20 '05 #11
VK

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?

Dec 20 '05 #12
VK wrote:
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?


Here is the post with the function code and error message.

http://groups.google.com/group/comp....e8cc4746ad43f3

Dec 20 '05 #13
VK

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.

Dec 20 '05 #14
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.




Dec 20 '05 #15
JRS: In article <4%*******************@newssvr27.news.prodigy.net> ,
dated Tue, 20 Dec 2005 12:42:40 local, seen in
news:comp.lang.javascript, Rick Brandt <ri*********@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"> ?

--
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.
Dec 20 '05 #16
Dr John Stockton wrote:
JRS: In article <4%*******************@newssvr27.news.prodigy.net> ,
dated Tue, 20 Dec 2005 12:42:40 local, seen in
news:comp.lang.javascript, Rick Brandt <ri*********@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.
Dec 21 '05 #17
JRS: In article <l2******************@newssvr12.news.prodigy.com >,
dated Wed, 21 Dec 2005 01:17:05 local, seen in
news:comp.lang.javascript, Rick Brandt <ri*********@hotmail.com> posted
:
Dr John Stockton wrote:
JRS: In article <4%*******************@newssvr27.news.prodigy.net> ,
dated Tue, 20 Dec 2005 12:42:40 local, seen in
news:comp.lang.javascript, Rick Brandt <ri*********@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.

--
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.
Dec 21 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by kf4pfw | last post: by
12 posts views Thread by StardogChampion | last post: by
78 posts views Thread by Robert Baer | last post: by
19 posts views Thread by pamelafluente | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.