...

View Full Version : Document.write error in a simple string.



a-9
08-28-2008, 01:49 PM
I have this piece of code inside an XHTML Strict document:

<script type="text/javascript"><!--//--><![CDATA[//><!--
var age = 27;
if (age > 17 && age < 21) {
document.write("<p>Old enough to vote, too young to drink.</p>");
}
//--><!]]>
</script>

It does not show up in the broser. (Opera and Firefox)
Edit: I have realized why I does now shows up: Logic. (I am ashamed)
The erros below still persist, though.
JSLint says:Error:
Implied global: document 3
Problem at line 3 character 9: document.write can be a form of eval.
Global age

I googled for this error but got nothing.
Thanks in advance for any help.

liorean
08-28-2008, 08:02 PM
document.write is an HTML DOM feature only and is not available in XHTML or generic XML modes. Look into using the DOM to generate the textnode and element and then insert it in the appropriate place in the DOM tree.

a-9
09-02-2008, 11:00 PM
OK. That sounds confusing to me. I am a beginner.

On my way in search of the acknowledgment I expect that soon I am going to master it. :)

waxdoc
09-03-2008, 02:34 AM
Just reviewed notes from "Professional JavaScript for Web Developers" and thought: WRITE() and WRITEIN() are BOM (Browser Object Model) document object methods and used in conjunction with .open() and .close()



var newWin = window.open (URL, "newWin", "features");
newWin.document.open;
newWin.document.write("______________");
newWin.document.close():


.open method called before using .write() and, after writing is complete, call .close(0 to render.

"Only object that belongs to both DOM and BOM is window.DOCUMENT." [Above is from my notes so don't blame to book for my errors.] And that probably has nothing to do with original query.

sybil6
09-03-2008, 12:05 PM
I have this piece of code inside an XHTML Strict document:

<script type="text/javascript"><!--//--><![CDATA[//><!--
var age = 27;
if (age > 17 && age < 21) {
document.write("<p>Old enough to vote, too young to drink.</p>");
}
//--><!]]>
</script>

It does not show up in the broser. (Opera and Firefox)
Edit: I have realized why I does now shows up: Logic. (I am ashamed)
The erros below still persist, though.
JSLint says:Error:
Implied global: document 3
Problem at line 3 character 9: document.write can be a form of eval.
Global age

I googled for this error but got nothing.
Thanks in advance for any help.

it surly doesnt show up as in your statement age is higher than 21, try it this way for example:

<script language="JavaScript" type="text/javascript">

var age = 27;
if (age > 17 && age < 28)
document.write('<p>Old enough to vote, too young to drink.</p>');


</script>
and it will work whatever the doctype is.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum