By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

nobody told me I couldn't...

P: n/a
OK, looked at the faq, went to faqts.com (discovered irt.org ain't
there and webdeveloper.com is
hung, but nil else), read every blessed thing I could find on events
and handlers at quirksmode
(superior site!) and webbasedprogramming.com (also informative) and
even checked moz for
gecko thingies (no help).

I gather I'm just too stoopid to write Js code. The snippet below hangs
when I touch the
"sayfoo/saybar" area, trying to load something. The javascript console
says nothing.

Nowhere does anybody say "you can't call document.write()" from inside
a mouse event handler. So much for putting print statements in your
code as a debugging tool, eh?

Nobody said you can't do stuff inside a span element, either.

So, what's up? Did someone forget to say "an interactive event handler
is a response to an asynchronous interrupt and certain I/O operations
are (only partially) masked thereby cratering your code", or is
something else afoot, like "G**d**mnned beginners can't figure
anything out!"?

Humbly, "Inquiring minds are dying to know..." :)

Ref: NS7.2 on Windoze XP.
<html>
<head>
<script type="text/javascript">

function gocyan() {
document.bgColor='cyan';
return false;
}
function gored() {
document.bgColor='red';
return false;
}
function lert1() {
alert("OK, the mouseover lerty thing works");
return false;
}
function sayfoo() {
document.write("foo on you");
return false; /* true doesn't help */
}
function saybar() {
document.write("stop that!");
return false;
}
function x_func() {
document.write('<p>This works...<span
id="cafeamericain">gocyan/gored</span><p>')
elem1=document.getElementById('cafeamericain')
elem1.onmouseover = gocyan;
elem1.onmouseout = gored;

document.write('<p>And this works...<span id="ingrid">gimme a
lert</span><p>')
elem2=document.getElementById('ingrid')
elem2.onmouseover = lert1;

document.write('<p>But this is weeeird...<span
id="ginjoints">sayfoo/saybar</span><p>')
elem3=document.getElementById('ginjoints')
elem3.onmouseover = sayfoo;
elem3.onmouseout = saybar;
}
</script>
</head>
<body>

<script type="text/javascript">
document.write("I'm gonna tear out my hair...<p>")
x_func()
document.write("one at a time.")
</script>

</body>
</html>

Dec 26 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
th******************@yahoo.com said the following on 12/26/2005 4:57 PM:
OK, looked at the faq, went to faqts.com (discovered irt.org ain't
there and webdeveloper.com is
hung, but nil else), read every blessed thing I could find on events
and handlers at quirksmode
(superior site!) and webbasedprogramming.com (also informative) and
even checked moz for
gecko thingies (no help).

I gather I'm just too stoopid to write Js code. The snippet below hangs
when I touch the
"sayfoo/saybar" area, trying to load something. The javascript console
says nothing.

Nowhere does anybody say "you can't call document.write()" from inside
a mouse event handler. So much for putting print statements in your
code as a debugging tool, eh?


http://jibbering.com/faq/#FAQ4_15

"How do I modify the current page in a browser? "

Using document.write after the page is finished loading replaces the
current page. So, if you use document.write to show messages, view
source, you will see only the message as it wipes out the current page.
Either use alert's or DynWrite for debugging - It will make your life
simpler.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 26 '05 #2

P: n/a
th******************@yahoo.com wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Who?
Subject: nobody told me I couldn't...
Subjects should provide a short abstract of the content of the posting, so
that the posting will attract the right people. They are not there to
convey your thoughts about anything.
[...]
Spare the rambling speech next time, thanks.
The snippet below hangs when I touch the "sayfoo/saybar" area, trying to
load something. The javascript console says nothing.

Nowhere does anybody say "you can't call document.write()" from inside
a mouse event handler.
Because that would not be true. You can call that method, however you have
to be aware that document.write() works differently when the document has
finished loading.
So much for putting print statements in your
code as a debugging tool, eh?
There are people here, including me, who know that calling document.write()
after the document has loaded will overwrite the document. Those people
have stated this fact and possible workarounds here on more than one
occasion.
Nobody said you can't do stuff inside a span element, either.
Because that would not be true either.
So, what's up? Did someone forget to say "an interactive event handler
is a response to an asynchronous interrupt and certain I/O operations
are (only partially) masked thereby cratering your code",
No, because that is a product of your imagination.
or is something else afoot, like "G**d**mnned beginners can't figure
anything out!"?
People who have not read any documentation before they started coding, thus
lacking a minimum clue about what they are doing, maybe cannot figure this
out.
Humbly, "Inquiring minds are dying to know..." :)
Pardon?
Ref: NS7.2 on Windoze XP.
Where the former is not up-to-date, but that does not matter here.
<html>
<head>
That is not Valid HTML. <URL:http://validator.w3.org/>
<script type="text/javascript">

function gocyan() {
document.bgColor='cyan';
The `bgcolor' attribute and respective properties are deprecated, learn to
use CSS and the respective style properties.
return false;
}
function gored() {
document.bgColor='red';
Ever considered using function arguments?
return false;
}
[...]
function x_func() {
document.write('<p>This works...<span
id="cafeamericain">gocyan/gored</span><p>') ^^
This is an ETAGO delimiter which must not occur in CDATA content.
See the W3C Validator result on how to fix this best.
elem1=document.getElementById('cafeamericain') ^^^^^
Undeclared global variable. Use the `var' keyword.

Test properties before you use them:
<URL:http://pointedears.de/scripts/test/whatami#inference>
elem1.onmouseover = gocyan;
elem1.onmouseout = gored;
[...]
See above.
[...]
document.write("I'm gonna tear out my hair...<p>")
x_func()
document.write("one at a time.")


Statements should be ended with a semicolon to avoid undesired side-effects
with automatic semicolon insertion by the script engine.

Consecutive calls of document.write() are inefficient and error-prone
regarding markup; call it once instead and build the string to be written
through concatenation or joining of Array elements.
PointedEars
Dec 26 '05 #3

P: n/a
On 2005-12-26, th******************@yahoo.com <th******************@yahoo.com> wrote:
function sayfoo() {
document.write("foo on you");
return false; /* true doesn't help */
}


function sayfoo() {
document.body.appendChild(document.createTextNode( "Foo On You "));
return false;
}
--

Bye.
Jasen
Dec 27 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.