"Richard" <An*******@127.001> wrote in message
news:ct*********@news3.newsguy.com...
On Mon, 24 Jan 2005 07:22:25 -0000 Hywel Jenkins wrote:
In article <ct*********@news3.newsguy.com>, An*******@127.001 says... <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.
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.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq