Javascript fails to work with xhtml 1.0 strict DTD

Discussion in 'Javascript' started by Paul Marsh, Sep 17, 2004.

  1. Paul Marsh

    Paul Marsh Guest

    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.someProperty; 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.
     
    Paul Marsh, Sep 17, 2004
    #1
    1. Advertisements

  2. Link pls.
     
    john henry bonham, Sep 17, 2004
    #2
    1. Advertisements

  3. Paul Marsh wrote:

    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, Sep 17, 2004
    #3
  4. A strange thing to do given how few scriptable dynamic browsers
    understand XHTML.
    So you don't care to mention what "function as normal" constitutes, or
    how "does not function" differs?
    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.
    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.
     
    Richard Cornford, Sep 17, 2004
    #4
  5. Paul Marsh

    Paul Marsh Guest

    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.
     
    Paul Marsh, Sep 18, 2004
    #5
  6. Paul Marsh

    Paul Marsh Guest

    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.
     
    Paul Marsh, Sep 18, 2004
    #6
  7. Words of warning have a tendency to be negative.
    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).
    Shoot yourself in the foot, why don't you? Welcome to the George Hester
    filter.

    Richard.
     
    Richard Cornford, Sep 18, 2004
    #7
  8. Paul Marsh

    cwdjr Guest

    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.
     
    cwdjr, Sep 19, 2004
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.