PageFade() with onLoad in <body> Good, with onClick in <a href> Bad??

P

Prisoner at War

Another weekend, another project, another problem....

Why should a perfectly fine function work only half-way through when
called through onClick in an anchor tag??

The text fade-in script below works when called through onLoad in the
<body> tag, but it "hangs" when called through onClick in <a
href="#">, as follows:

<script language="JavaScript1.2">

var hex=240;

function FadePage()
{
if (hex>0)
{
hex-=11;
document.getElementById("text").style.color="rgb("+hex+","+hex
+","+hex+")";
setTimeout("FadeText()",20);
}
else
{
hex=240;
}
}
</script>


I have a <div> with an id of "text"...again, it all fades in fine when
called through onLoad in the <body> tag but seems to stall at
setTimeout(...) -- maybe it doesn't even get to it at all; the text
just fades in half-way and stays that way, never completing the fade-
in process.

Now why should that be??


TIA!!
 
H

Holger Jeromin

Prisoner at War schrieb am 26.04.2008 18:55:
Another weekend, another project, another problem....

Why should a perfectly fine function work only half-way through when
called through onClick in an anchor tag??

The text fade-in script below works when called through onLoad in the
<body> tag, but it "hangs" when called through onClick in <a
href="#">, as follows:

<script language="JavaScript1.2">

Just write javascript.
var hex=240;

function FadePage()
{
if (hex>0)
{
hex-=11;
document.getElementById("text").style.color="rgb("+hex+","+hex
+","+hex+")";
setTimeout("FadeText()",20);
}
else
{
hex=240;
}
}
</script>

I have a <div> with an id of "text"...again, it all fades in fine when
called through onLoad in the <body> tag but seems to stall at
setTimeout(...) -- maybe it doesn't even get to it at all; the text

Test this with alerts before and after the style.color rule.
just fades in half-way and stays that way, never completing the fade-
in process.

Now why should that be??

Wich Browser showed this problem?
 
P

Prisoner at War

Just write javascript.

I dunno, I've always like useless little details like that!
Test this with alerts before and after the style.color rule.

Hmmm, okay, what do you suspect? If an alert() comes up, before or
after, what of it?
Wich Browser showed this problem?

Well, actually, now that you ask...Opera 9 and IE 7 just ignore the
whole thing and display the page, without any fading-in effect...FF 2
is what gets "stalled" like half-way through....
 
G

Gregor Kofler

Prisoner at War meinte:
Another weekend, another project, another problem....

Why should a perfectly fine function work only half-way through when
called through onClick in an anchor tag??

The text fade-in script below works when called through onLoad in the
<body> tag, but it "hangs" when called through onClick in <a
href="#">, as follows:

<script language="JavaScript1.2">

....type="text/javascript".... language is neither needed, nor standard
compliant.
var hex=240;

function FadePage()
{
if (hex>0)
{
hex-=11;
document.getElementById("text").style.color="rgb("+hex+","+hex
+","+hex+")";
setTimeout("FadeText()",20);

What or where is "FadeText()"? Or did you mean FadePage()?

Gregor
 
H

Holger Jeromin

Prisoner at War schrieb am 27.04.2008 00:43:
I dunno, I've always like useless little details like that!

I said, that you should not specify the javascript version in this tag.
Hmmm, okay, what do you suspect? If an alert() comes up, before or
after, what of it?

you said, that you have no idea, if the browser reaches this point of
your code. You can test this with a few alerts...
 
P

Prisoner at War

Prisoner at War meinte:





...type="text/javascript".... language is neither needed, nor standard
compliant.

I see that now! Goodness, why all this messing around all the time
with depreciating tags and attributes...reminds me of how Microsoft
moves things around in MS Word, etc.
What or where is "FadeText()"? Or did you mean FadePage()?

Yes, you are correct: I meant "FadePage ()" -- "FadeText()" is just
another name; sorry for the confusion!
 
P

Prisoner at War

I said, that you should not specify the javascript version in this tag.
<script language="JavaScript"> is better.

I know, I know: W3C standards compliance. I wonder why they keep
changing these standards, though. Now "type" is the preferred
attribute -- and instead of "text/JavaScript" they will want
"application/JavaScript" next!
you said, that you have no idea, if the browser reaches this point of
your code. You can test this with a few alerts...

Yes, but then what...I mean, what if it never reaches that point in
the code, and what if it does? What would it mean -- why would
reaching or not reaching that point cause the effect?

I'm trying to figure out what the FF2 browser is "thinking" WRT that
code...IE7 and Opera 9 seem to totally ignore it. Is the code itself
wrong? Why does it work onLoad in the <body> tag but not onClick in
 
T

Thomas 'PointedEars' Lahn

Gregor said:
Prisoner at War meinte:

...type="text/javascript".... language is neither needed,
Correct.

nor standard compliant.

Wrogn. The `language' attribute of the `script' element is specified in the
Web standards HTML 4.01 Transitional [1], and XHTML 1.0 Transitional [2].

It is not specified in the Web standard HTML 3.2 as the `script' element has
no attributes there.[3] It is not specified in the Web standards HTML 4.01
Strict [4], and XHTML 1.0 Strict [5], because it is *deprecated* for obvious
reasons.[6] (JFTR, the `script' element is not specified in ISO/IEC
15445:200(E) at all.[6])


PointedEars
___________
[1] http://www.w3.org/TR/1999/REC-html401-19991224/sgml/loosedtd.html
[2]
http://www.w3.org/TR/2002/REC-xhtml1-20020801/dtds.html#a_dtd_XHTML-1.0-Transitional
[3] http://www.w3.org/TR/REC-html32
[4] http://www.w3.org/TR/1999/REC-html401-19991224/sgml/strictdtd.html
[5]
http://www.w3.org/TR/2002/REC-xhtml1-20020801/dtds.html#a_dtd_XHTML-1.0-Strict
[6]
http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.1
[7] https://www.cs.tcd.ie/15445/TC1.html
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top