Proper DOCTYPE breaks JavaScript in IE9

P

P E Schoen

I've been playing with a simple HTML document which contains JavaScript in
the <HEAD>. It worked fine without proper DOCTYPE, but when I fixed that so
it validated, the JavaScript would not run. At first it was also broken in
Firefox but I changed the DOCTYPE slightly as recommended on one forum and
it worked - but still not in IE9.

There's also a somewhat puzzling complaint about a </P> that passed
validation in the first instance but not the second.

Here's my HTML:
http://www.enginuitysystems.com/ForceCalculator1.htm

I start as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" >
<TITLE>Force Calculator</TITLE>

<SCRIPT type="text/javascript"> //!-- Beginning of JavaScript -

And the complaint is here (around line 150):

<P>
<h2>Torque, Power, and RPM</h2>
<!-- </P> -->

I referred to the following, but I note that the SCRIPT in the header is an
external reference and the inline script is in the BODY. Maybe I'll try
that.

I haven't done anything with JavaScript (or HTML for that matter) for
awhile, so I'm quite rusty. This may be an obvious error but I'm stumped for
now.

Thanks!

Paul
www.muttleydog.com
 
P

P E Schoen

"Doug Miller" wrote in message
Yes, that *is* rather a lot. Had you considered fixing them?

I can fix the errors by adding a DOCTYPE. But that breaks JavaScript for
IE9.

Paul
 
P

P E Schoen

I found that the keyword const is not allowed in Javascript, although
apparently Firefox and Chrome allow it. The debugger complained about
something else and then finally it continued to the const declaration where
it reported a syntax error.

So many languages. So much inconsistency...

Paul
 
T

Tim Streater

P E Schoen said:
I found that the keyword const is not allowed in Javascript, although
apparently Firefox and Chrome allow it. The debugger complained about
something else and then finally it continued to the const declaration where
it reported a syntax error.

So many languages. So much inconsistency...

No, just the one. I observe that Safari is very forgiving, reporting no
errors in the error console. Not only it doesn't mind your consts, it
also allows you to do (e.g.):

Form1.FormDate.value = EditDate;

rather than:

document.Form1.FormDate.value = EditDate;

or even:

document.forms["Form1"].FormDate.value = EditDate;

OK, so you took out the consts. What happened then?
 
P

P E Schoen

"Doug Miller" wrote in message
Really? What DOCTYPE is that?

Almost any DOCTYPE. The validation errors were mostly related to that. But
the broken JavaScript was due to other factors that did not affect
validation.

The problem(s) are fixed now, at least to the point where it works.

Thanks,

Paul
 
H

Hot-Text

P E Schoen said:
This simpler HTML page works OK in IE9:
http://www.enginuitysystems.com/CalculateJS1.htm

But it has 8 errors and 2 warnings. That's a lot for 60 lines of highly
expanded HTML.

Paul

Not
<SCRIPT type="text/javascript">
//!-- Beginning of JavaScript -

// - End of JavaScript - -->
</SCRIPT>

But
<SCRIPT type="text/javascript">
<!--
// Beginning of JavaScript -

// - End of JavaScript
//-->
</SCRIPT>

Have to be start <!-- to work in IE........
 
J

Jonathan N. Little

Hot-Text said:
Not
<SCRIPT type="text/javascript">
//!-- Beginning of JavaScript -

// - End of JavaScript - -->
</SCRIPT>

But
<SCRIPT type="text/javascript">
<!--
// Beginning of JavaScript -

// - End of JavaScript
//-->
</SCRIPT>

No that is absolutely incorrect. The first is missing the leading "<"
but is unnecessary you do not have to "hide" with HTML comments
JavaScript within an HTML document, nor CSS within the STYLE element as
many do. That was for a bug in an ancient, and I mean *ancient* version
of Netscape.

Your suggestion is wrong because between the opening and closing SCRIPT
tags "plays" by JavaScript, not HTML syntax which are C, C+++ style:

// valid JavaScript comment

/* another JavaScript comment */

not

<!-- invalid JavaScript comment -->
 
P

P E Schoen

"Robert Baer" wrote in message
You really mean "so many versions of IE, an almost infinite amount of
inconsistency".

No, I'm referring to the sometimes subtle and sometimes just puzzling and
annoying differences in languages such as JavaScript, PHP, Perl, C, Delphi,
and Visual Basic, to name a few. Strongly or loosely typed. Case sensitive
or not. Things like that.

But the browsers also contribute to the problem when they don't work the
same.

I mostly use C for microcontroller projects (assembler for simple stuff),
Borland Delphi4 for Windows GUIs, JavaScript for client side scripts, PHP
for server side scripts (I tried but didn't like Perl), VBA for application
scripting, and sometimes VB or JS using the WSH for local machine scripts.
It's difficult to remember the standards and quirks for each when switching
back and FORTH (and that's another language!)

Paul
 
J

Jonathan N. Little

P said:
"Robert Baer" wrote in message


No, I'm referring to the sometimes subtle and sometimes just puzzling
and annoying differences in languages such as JavaScript, PHP, Perl, C,
Delphi, and Visual Basic, to name a few. Strongly or loosely typed. Case
sensitive or not. Things like that.

But the browsers also contribute to the problem when they don't work the
same.

I mostly use C for microcontroller projects (assembler for simple
stuff), Borland Delphi4 for Windows GUIs, JavaScript for client side
scripts, PHP for server side scripts (I tried but didn't like Perl), VBA
for application scripting, and sometimes VB or JS using the WSH for
local machine scripts. It's difficult to remember the standards and
quirks for each when switching back and FORTH (and that's another
language!)

The same is true for "human" languages. Since humans created computer
languages I would say "inconsistency" is in our nature! ;-)
 
P

P E Schoen

"Jonathan N. Little" wrote in message
The same is true for "human" languages. Since humans created computer
languages I would say "inconsistency" is in our nature! ;-)

At least K&R's C language and Pascal/Delphi were created with the idea of
making them logical and consistent. They differ on some important points but
otherwise they are fairly easy to understand and use. BASIC has always been
a bit of a kludge, but it was pretty good for beginners and was adequate for
simple programs and it was/is well suited to interpretive use.

But then OOP became popular and C++ and VB seemed to be hacked to make them
fit the need, but I think Delphi was easier to use because it was already a
higher level language than C. But IMHO VB was never really consistent and
powerful enough in its design, and Visual BASIC seems to be very quirky and
unwieldy. DotNet I think was a further abomination.

OTOH client side scripting with JavaScript seems close enough to C for me to
be comfortable, but its quirks are rather annoying. And the popular server
side scripting languages Perl and PHP seem to have been fudged and tweaked
from the git-go by code monkeys who did not really have an overall plan and
just used bits and pieces of other languages along with some of their own
often questionable and obfuscating constructs such as "regular expressions".
But at least they seem to have some consistency among the languages. Others
such as Ruby seem to be "me-too" variations designed by young hotshot
programmers to be useful for specific applications but not well enough
designed to to be comprehensive and well structured.

Oh, well, it is what it is. And I read an article recently praising the
merits of Ada, which at least is similar to Pascal and has some nice
features that make it easy to read and somewhat bug-resistant.

Paul
 
H

Hot-Text

Jonathan N. Little said:
No that is absolutely incorrect. The first is missing the leading "<"
but is unnecessary you do not have to "hide" with HTML comments
JavaScript within an HTML document, nor CSS within the STYLE element as
many do. That was for a bug in an ancient, and I mean *ancient* version
of Netscape.

Your suggestion is wrong because between the opening and closing SCRIPT
tags "plays" by JavaScript, not HTML syntax which are C, C+++ style:

// valid JavaScript comment

/* another JavaScript comment */

not

<!-- invalid JavaScript comment -->

/* Yes JavaScript comment */

You a 100% Right Jonathan N. Little
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top