nobody told me I couldn't...

  • Thread starter throwaway_addr_12345
  • Start date
T

throwaway_addr_12345

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>
 
R

Randy Webb

(e-mail address removed) 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.
 
T

Thomas 'PointedEars' Lahn

(e-mail address removed) 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. said:
<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:
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
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top