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

Discussion in 'Javascript' started by Prisoner at War, Apr 26, 2008.

  1. 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!!
     
    Prisoner at War, Apr 26, 2008
    #1
    1. Advertising

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

    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?

    --
    Mit freundlichen Grüßen
    Holger Jeromin
     
    Holger Jeromin, Apr 26, 2008
    #2
    1. Advertising

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

    On Apr 26, 3:27 pm, Holger Jeromin <> wrote:
    >
    >
    > 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....

    > --
    > Mit freundlichen Grüßen
    > Holger Jeromin
     
    Prisoner at War, Apr 26, 2008
    #3
  4. Re: PageFade() with onLoad in <body> Good, with onClick in <a href>Bad??

    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


    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 26, 2008
    #4
  5. Re: PageFade() with onLoad in <body> Good, with onClick in <a href>Bad??

    Prisoner at War schrieb am 27.04.2008 00:43:
    > On Apr 26, 3:27 pm, Holger Jeromin <> wrote:
    >>> <script language="JavaScript1.2">

    >> Just write javascript.

    > I dunno, I've always like useless little details like that!


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

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


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

    --
    Mit freundlichen Grüßen
    Holger Jeromin
     
    Holger Jeromin, Apr 27, 2008
    #5
  6. Re: PageFade() with onLoad in <body> Good, with onClick in <a href>Bad??

    Holger Jeromin meinte:

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


    Why? This attribute is deprecated and useless (unless you are writing
    for some browsers of ancient times). However, if you want valid markup
    you have to provide a type attribute. [1]

    Gregor


    [1] <http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1>



    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 28, 2008
    #6
  7. Re: PageFade() with onLoad in <body> Good, with onClick in <a href>Bad??

    On Apr 26, 6:44 pm, Gregor Kofler <> wrote:
    > 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.


    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.

    > > 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()?


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

    > <SNIP>
     
    Prisoner at War, Apr 28, 2008
    #7
  8. Re: PageFade() with onLoad in <body> Good, with onClick in <a href>Bad??

    On Apr 27, 4:23 pm, Holger Jeromin <> wrote:
    >
    >
    > 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
    an <a href> anchor tag??

    > --
    > Mit freundlichen Grüßen
    > Holger Jeromin
     
    Prisoner at War, Apr 28, 2008
    #8
  9. Re: PageFade() with onLoad in <body> Good, with onClick in <a href>Bad??

    Gregor Kofler wrote:
    > Prisoner at War meinte:
    >> <script language="JavaScript1.2">

    >
    > ...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
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Apr 29, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    203,760
    Adrienne Boswell
    Jun 20, 2006
  2. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    614
    Martin Honnen
    Nov 4, 2004
  3. Replies:
    2
    Views:
    628
  4. Replies:
    1
    Views:
    96
    Robert
    Jul 14, 2005
  5. Vincent van Beveren

    BASE HREF and A HREF="#" onclick="..."

    Vincent van Beveren, Jul 6, 2006, in forum: Javascript
    Replies:
    2
    Views:
    427
    Vincent van Beveren
    Jul 6, 2006
Loading...

Share This Page