By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

Javascript fails to work with xhtml 1.0 strict DTD

P: n/a
Hello everyone,

I am attempting to create a xhtml page that uses a bit of dhtml.
The javascript I am using uses
document.getElementById('someId').style.someProper ty; and is and
external script. My page uses this dtd:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

It validates at the wc3 validator as correct xhtml, but the problem is
my script does not function. When I remove the dtd, the script
functions as normal.

I am obviously missing something here and would appreciate any
feedback.

Paul Marsh.
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Paul Marsh wrote:
Hello everyone,

I am attempting to create a xhtml page that uses a bit of dhtml.
The javascript I am using uses
document.getElementById('someId').style.someProper ty; and is and
external script. My page uses this dtd:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

It validates at the wc3 validator as correct xhtml, but the problem is
my script does not function. When I remove the dtd, the script
functions as normal.

I am obviously missing something here and would appreciate any
feedback.

Paul Marsh.


Link pls.
Jul 23 '05 #2

P: n/a


Paul Marsh wrote:

I am attempting to create a xhtml page that uses a bit of dhtml.
The javascript I am using uses
document.getElementById('someId').style.someProper ty; and is and
external script. My page uses this dtd:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

It validates at the wc3 validator as correct xhtml, but the problem is
my script does not function. When I remove the dtd, the script
functions as normal.

I am obviously missing something here and would appreciate any
feedback.


What exactly are you trying to do? Which browser fails? An error
messages or warning given by the browser?
If you include such a DOCTYPE declaration browsers like Mozilla or
Netscape 6/7 switch to standard compliants mode and therefore ignore
things like
element.style.left = 200
as that is not correct CSS, a unit is missing so you need
element.style.left = '200px';
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

P: n/a
Paul Marsh wrote:
I am attempting to create a xhtml page that uses a bit
of dhtml.
A strange thing to do given how few scriptable dynamic browsers
understand XHTML.
The javascript I am using uses
document.getElementById('someId').style.someProper ty;
and is and external script. My page uses this dtd:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

It validates at the wc3 validator as correct xhtml, but the
problem is my script does not function. When I remove the dtd,
the script functions as normal.
So you don't care to mention what "function as normal" constitutes, or
how "does not function" differs?
I am obviously missing something here
Yes; code, context and explanation. Indeed this is a case for a URL to
the page (or a cut down page demonstrating the problem alone) because it
isn't even certain that you are creating an XHTML document, rather than
a malformed HTML document that syntactically resembles XHTML, and there
for it isn't possible to tell if it is an HTML DOM or an XHTML DOM that
you are actually scripting.
and would appreciate any feedback.


Without any pertinent information to go on any answer is ginning to be a
guess. And given that there are probably an infinite number of ways of
creating erroneous and fragile scripts a guess is such a long shot that
it is hardly worth writing, and definitely doesn't warrant any
explanation:-

The formal doctype is putting the browser into 'CSS1Compat' mode and the
assignments of non-zero values to dimensions-type style properties do
not include the required units declaration.

Richard.
Jul 23 '05 #4

P: n/a
Hi Richard,

yes in hindsight of course I should have included some additional
info... it was my first post and I'll be sure to
be more careful next time.

As for this: "A strange thing to do given how few scriptable dynamic
browsers understand XHTML."

That's a fairly negitive tone, I'm here 'cause I don't know all the
answers.

You complain that it's not certain my document is xhtml, but I mentioned
in my post that it validates at the wc3 validator as correct xhtml.

Anyway, it works now that I have declared the units so thanks, but you
should probably get out more.

Paul.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5

P: n/a
Hi Martin,

yes, now that I have declared the units it works. I'll be sure to
include more detailed information in future posts.
Thanks for your reply, I'd better go do some more reading!

Paul.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

P: n/a
Paul Marsh wrote:
Hi Richard,
yes in hindsight of course I should have included some
additional info... it was my first post and I'll be
sure to be more careful next time.

As for this: "A strange thing to do given how few scriptable
dynamic browsers understand XHTML."

That's a fairly negitive tone, I'm here 'cause I don't
know all the answers.
Words of warning have a tendency to be negative.
You complain that it's not certain my document is xhtml, but I
mentioned in my post that it validates at the wc3 validator as
correct xhtml.
That is totally irrelevant to a web browser, if you send a content-type
header of text/html then the browser sees the document as (malformed)
HTML and builds an HTML DOM to be scripted. And if you send a correct
XHTML content-type header IE browsers cannot display the results, making
that a non-viable option in a commercial contexts. Which leaves
server-side content negotiation as the only way of using real XHTML and
accommodating IE, with the consequence that you will probably also need
to send a different script designed to work with each of the two types
of DOM (and that is a lot of extra effort in order to use XHTML, with
extremely questionable returns).
Anyway, it works now that I have declared the units so thanks,
but you should probably get out more.


Shoot yourself in the foot, why don't you? Welcome to the George Hester
filter.

Richard.
Jul 23 '05 #7

P: n/a
I have converted several old dhtml codes from the browser war era to
modern single path getElementById. It is very common to find problems
with codes from this era when you clean them up for a specific
Doctype. For example, after you strip layers and document.all support
from one of the fireworks scripts at DynamicDrive and clean it up to
4.01 transitional standards, all is fine on several modern browsers.
However if you just change to html 4.01 strict with the DOCTYPE
required for it, the script fails completely on some browsers. The
problem in such cases usually can be traced down to the CSS. I have
seen units such as px used for top and left, but not for width and
height. For moving things, I have seen such as blah.left=40 or
blah.left=x instead of the now required blah.left=40px or
blah.left=x+'px' . The faulty codes often will work on the IE6
browser, but not on Opera and the Mozilla family - Big
Mozilla(Mozilla), Baby Mozilla(FireFox), and Fat Mozilla(Netscape). So
the place I start when I have this sort of problem is to check
everything in the script and html that has anythig to do with CSS and
ask myself if the expression needs a unit in addition to a number.
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.