function / function() / window.onload=

Q

Q

Question:

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

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

(IE)
???
 
R

RobG

Q said:
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! :)
 
E

Evertjan.

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.
 
J

JCO

Where's the function recalculate() at?

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

Randy Webb

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.
 
T

Tim

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


To answer the question, it doesn't matter.


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.
http://www.JavascriptToolbox.com/bestpractices/
 
J

JCO

Sorry Randy

Randy Webb said:
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?


To answer the question, it doesn't matter.


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.
http://www.JavascriptToolbox.com/bestpractices/
 
Q

Q

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
 

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,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top