Forum Moderators: open

Message Too Old, No Replies

XHTML DTD poblematic for JavaScript?

I'm grasping at straws to get a script working

         

RichardOnRails

6:45 pm on Nov 24, 2010 (gmt 0)

10+ Year Member



Hi,

I saw somewhere on the Web that XHTML DTD is poblematic for JavaScript because of the uses of braces in JavaScript "programs". I found that comment as I searched for a solution to my original problem. to wit:

I've got an HTML file displayed at [pastie.org...]

The Firefox 3.6.12 displays only:
=========== Start ===========
10_ShowClassesAndTypes
Starting 10_ShowClassesAndTypestesting dw
=========== End ============

The "dw" function writes nothing. Suggestion on how to get "shorthand document.write" function working would be greatly appreciated. In the meantime I'm going to see if I can get Protype to provide a shorthand function.

It's been suggested that document.write() is not a dynamic method. Called within a function it will simply rewrite the document (as it would be a new session).

Any ideas?

Best wishes,
Richard

Fotiman

7:21 pm on Nov 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld! document.write is generally frowned upon. When called after the page has loaded, it will replace the existing document. Better alternatives would be to use the DOM methods like appendChild, createElement, etc. In your example, it appears to be working correctly, though. Your script is doing this:

    

10_ShowClassesAndTypes



And then the output is, as you listed:

10_ShowClassesAndTypes
Starting 10_ShowClassesAndTypestesting dw


You then wrote that the dw function writes nothing, but that statement is incorrect. I can see from your results that it wrote "testing dw" as expected.

RichardOnRails

7:56 pm on Nov 24, 2010 (gmt 0)

10+ Year Member



Wow! Great response!
I didn't notice that little "testing dw" string hanging at the end.
I am so impressed that you looked my post that carefully.

Of course, when I ran my test again with this new knowledge, I saw what I have overlooked. So I belatedly stuck a "<br>" at the of the long string and got what I had always pictured in my mind.

Thank you very much,
Richard

JAB Creations

3:55 am on Nov 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't use the XHTML doctype unless you're going to serve the page as actual XHTML which means using the application/xhtml+xml media type and you should use it as it'll benefit your learning greatly and help establish stricter more competent code and trust me it's so worth it if you stick to figuring out how to make it all work. Using document.write and innerHTML are two things you'll never catch me willingly using. Fotiman will disagree though I'm sticking to my guns on this and we've agreed to disagree on the topic. :)

- John