function / function() / window.onload=

Discussion in 'Javascript' started by Q, Mar 24, 2006.

  1. Q

    Q Guest

    Question:

    why doesn't:
    window.onLoad = recalculate();

    work, and do I have to use:
    window.onLoad = recalculate;

    (IE)
    ???
     
    Q, Mar 24, 2006
    #1
    1. Advertising

  2. Q

    RobG Guest

    Q wrote:
    > Question:
    >
    > why doesn't:
    > window.onLoad = recalculate();


    That will assign the result of calling the recalculate() function to the
    onload event. Onload will try to execute it later. If the result is
    not a reference to a function (or something that onload can execute)
    you'll likely get an error.


    > work, and do I have to use:
    > window.onLoad = recalculate;


    That will assign a reference to the recalculate function, so that it
    will be executed when the onload event fires.

    Incidentally, *neither* of them will 'work' because JavaScript is case
    sensitive and you want to access the _onload_ property, not onLoad (note
    capitalisation).

    Hope that helped! :)


    --
    Rob
     
    RobG, Mar 24, 2006
    #2
    1. Advertising

  3. Q

    Evertjan. Guest

    Q wrote on 24 mrt 2006 in comp.lang.javascript:

    > Question:
    >
    > why doesn't:
    > window.onLoad = recalculate();
    >
    > work, and do I have to use:
    > window.onLoad = recalculate;


    Because

    window.onLoad = recalculate();

    tries to fill the "value" of window.onLoad immediately with the returned
    result of recalculate()

    and when the body is loaded it will execute
    the earlier result string "false" or "23", which is not executeble.

    while

    window.onLoad = recalculate;

    defines window.onLoad as being the same as the function recalculate(),
    and so will only execute the script content of recalculate() when the body
    is loaded.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Mar 24, 2006
    #3
  4. Q

    JCO Guest

    Where's the function recalculate() at?

    <script language="javascript" type="text/javascript">
    <!--
    function recalculate()
    {
    //do work
    ....
    }
    // -->
    </script>



    "Q" <> wrote in message
    news:44240c06$0$11065$4all.nl...
    > Question:
    >
    > why doesn't:
    > window.onLoad = recalculate();
    >
    > work, and do I have to use:
    > window.onLoad = recalculate;
    >
    > (IE)
    > ???
    >
    >
     
    JCO, Mar 24, 2006
    #4
  5. Q

    Randy Webb Guest

    JCO said the following on 3/24/2006 11:42 AM:

    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?

    > Where's the function recalculate() at?


    To answer the question, it doesn't matter.

    > <script language="javascript" type="text/javascript">


    language attribute is deprecated, drop it.

    > <!--


    Attempting to hide content of script elements has been a bad practice
    longer than the language attribute has been deprecated.

    If you want to ask/answer questions, do so. But at least do some
    research before you do and find the bad habits in your own coding
    because if you don't then they *will* be pointed out to you.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Mar 24, 2006
    #5
  6. Q

    Tim Guest

    JCO does not know if recalculate() was a "written code" done by "Q".
    He just offered the suggestion, that if it was a script that "Q" wrote,
    there may be a problem else where (like in the code).

    I don't think he intended to offend those like Randy.

    "Randy Webb" <> wrote in message
    news:...
    > JCO said the following on 3/24/2006 11:42 AM:
    >
    > Answer:It destroys the order of the conversation
    > Question: Why?
    > Answer: Top-Posting.
    > Question: Whats the most annoying thing on Usenet?
    >
    > > Where's the function recalculate() at?

    >
    > To answer the question, it doesn't matter.
    >
    > > <script language="javascript" type="text/javascript">

    >
    > language attribute is deprecated, drop it.
    >
    > > <!--

    >
    > Attempting to hide content of script elements has been a bad practice
    > longer than the language attribute has been deprecated.
    >
    > If you want to ask/answer questions, do so. But at least do some
    > research before you do and find the bad habits in your own coding
    > because if you don't then they *will* be pointed out to you.
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices -

    http://www.JavascriptToolbox.com/bestpractices/
     
    Tim, Mar 24, 2006
    #6
  7. Q

    JCO Guest

    Sorry Randy

    "Randy Webb" <> wrote in message
    news:...
    > JCO said the following on 3/24/2006 11:42 AM:
    >
    > Answer:It destroys the order of the conversation
    > Question: Why?
    > Answer: Top-Posting.
    > Question: Whats the most annoying thing on Usenet?
    >
    > > Where's the function recalculate() at?

    >
    > To answer the question, it doesn't matter.
    >
    > > <script language="javascript" type="text/javascript">

    >
    > language attribute is deprecated, drop it.
    >
    > > <!--

    >
    > Attempting to hide content of script elements has been a bad practice
    > longer than the language attribute has been deprecated.
    >
    > If you want to ask/answer questions, do so. But at least do some
    > research before you do and find the bad habits in your own coding
    > because if you don't then they *will* be pointed out to you.
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices -

    http://www.JavascriptToolbox.com/bestpractices/
     
    JCO, Mar 24, 2006
    #7
  8. Q

    Q Guest

    Ok!!.
    Thank you guys for your time!!
    It's a little bit more clear for me now :)

    recalculate() was a function to 'recalculate' a grand-total in a
    webbased-form.
    When the page loads i have to recalculate the form with values retrieved
    from database..

    (The quick-fix was the answer from Rob... case-sensitive.. didn't know
    that!!!)

    Thanx again

    Regards,
    Marco


    "Q" <> schreef in bericht
    news:44240c06$0$11065$4all.nl...
    > Question:
    >
    > why doesn't:
    > window.onLoad = recalculate();
    >
    > work, and do I have to use:
    > window.onLoad = recalculate;
    >
    > (IE)
    > ???
    >
     
    Q, Mar 27, 2006
    #8
    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. Fabio R.
    Replies:
    0
    Views:
    843
    Fabio R.
    Mar 25, 2005
  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:
    5
    Views:
    316
    Thomas 'PointedEars' Lahn
    May 15, 2005
  4. Replies:
    18
    Views:
    556
  5. marco

    onload -->* no onload

    marco, Jun 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    228
    marco
    Jun 24, 2006
Loading...

Share This Page