bob wrote:
Hi,
consider this script:
<script>
function doIt()
{
alert("ok")
}
document.onclick=doIt // or document.onclick=doIt()
</script>
Generally, does it make a difference when there is no parameter to pass?
And when there is a parameter to pass?
This has nothing to do with parameter passing. If you have
document.onclick = doIt;
then you assign the function doIt to the onclick property. However if
you have
document.onclick = doIt();
then you call the function doIt and assign the result of the function
call to the onclick property of the document object. The result of
calling doIt in your example is the value undefined, thus you assign the
value undefined to the onclick property. Therefore what you want is
document.onclick = doIt;
If you want to pass parameters to doIt then you need to use
document.onclick = function (evt) {
doIt('arg');
};
--
Martin Honnen
http://JavaScript.FAQTs.com/