Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > function / function() / window.onload=

Reply
Thread Tools

function / function() / window.onload=

 
 
Q
Guest
Posts: n/a
 
      03-24-2006
Question:

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

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

(IE)
???


 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      03-24-2006
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
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      03-24-2006
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)
 
Reply With Quote
 
JCO
Guest
Posts: n/a
 
      03-24-2006
Where's the function recalculate() at?

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



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



 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-24-2006
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/
 
Reply With Quote
 
Tim
Guest
Posts: n/a
 
      03-24-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> 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/


 
Reply With Quote
 
JCO
Guest
Posts: n/a
 
      03-24-2006
Sorry Randy

"Randy Webb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> 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/


 
Reply With Quote
 
Q
Guest
Posts: n/a
 
      03-27-2006
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" <(E-Mail Removed)> schreef in bericht
news:44240c06$0$11065$(E-Mail Removed)4all.nl...
> Question:
>
> why doesn't:
> window.onLoad = recalculate();
>
> work, and do I have to use:
> window.onLoad = recalculate;
>
> (IE)
> ???
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function versus pointer to function, in context of std::function,huh? Alf P. Steinbach C++ 10 07-27-2011 05:51 AM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments