Is basic crapola the norm for describing how to implement JS?

R

Richard

<begin rant>

I am so damn sick and tired of seeing how NOT to use document.write() it's
driving me frickin nuts.

This is OUR explanation of document.write().
document.write("hello idiot")
document.write(<p>)
document.write(<tr>)

I mean come on. Why do I need to use javascript to write html tags?
Let alone simple plain text messages?

This is not the purpose of document.write().
It's purpose is to allow the user to write to the document meaningful output
as defined in various statements within the ().
Such as document.write(a+b+c-x).

Some of these good minded jackasses even take it a bit further and show:
<h2>some text</h2>
<script> <<< shortened on purpose ok?
document.write(<p>)
</script>

I kid you not.

And of course, I've seen examples of a short simple paragraph explaining
what it is and a dozen ads surrounding it.

I swear, some people are putting up pages just to get hits so the
advertisers pay them more.

< end rant>
 
H

Hywel Jenkins

<begin rant>

I am so damn sick and tired of seeing how NOT to use document.write() it's
driving me frickin nuts.

This is OUR explanation of document.write().
document.write("hello idiot")
document.write(<p>)
document.write(<tr>)

I mean come on. Why do I need to use javascript to write html tags?

You don't. However, the code you've copied may do it. There are
perfectly valid reasons for doing that sort of this, RtS. See if you
can think of anything, dum-dum.
 
R

Richard

You don't. However, the code you've copied may do it. There are
perfectly valid reasons for doing that sort of this, RtS. See if you
can think of anything, dum-dum.

I understand it is shown for demonstration purposes, but can somebody please
get an original idea?
It's like one person wrote the thing, and 10,000 others copied it.
While none of them truly explain the purpose or how else it may be used.
 
G

Grant Wagner

Richard said:
I understand it is shown for demonstration purposes, but can somebody
please
get an original idea?
It's like one person wrote the thing, and 10,000 others copied it.
While none of them truly explain the purpose or how else it may be
used.

Because the output of document.write() depends on JavaScript being
enabled, you can use document.write() to control the content of your
page that may depend on JavaScript:

<body onload="blah(false);">
<form name="myForm">
<script type="text/javascript">
document.write(
'<input type="checkbox"' +
' name="myCheckbox"' +
' onclick="blah(this.checked);">' +
' Additional comments'
);
function blah(b)
{
var el;
if (document.getElementById &&
(el = document.getElementById('myAdditionalComments')) &&
(el = el.style) &&
'string' == typeof el.display)
{
el.display = b ? '' : 'none';
return el.display = b ? '' : 'none';
}
}
</script>
<input type="text" id="myAdditionalComments" name="additionalComments">
</form>

While you may not be able to infer that document.write() working means
the browser also supports document.getElementById, or the ability to
dynamically change an element's display style, you are guaranteed that
in the absense of JavaScript, you will never get a checkbox that does
nothing.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top