Why is onClick Firing Immediately?

Hello there.

This is baffling me. I haven’t done any Javascript in quite awhile, but I know this is supposed to work. Somehow it isn’t;

window.onload = function()
	{
	document.getElementById('Track01_Bubble01').onclick = myFunction();
	}
function myFunction()
	{
	alert('Hello World!');
	}

Somehow the function is being triggered as soon as the page loads, and it’s not when I click on ‘Track01_Bubble01’.

Does anyone see anything that I’m missing? I’m totally stuck.

hmm… Dropping it into an anonymous function seems to have solved it;

<script type="text/javascript">
	window.onload = function()
		{
		document.getElementById('Track01_Bubble01').onclick = function()
			{
			myFunction();
			}
		}
</script>
window.onload = function()
	{
	document.getElementById('Track01_Bubble01').onclick = myFunction[SIZE=4][COLOR="#FF0000"]()[/COLOR][/SIZE];
[COLOR="#FF0000"]                                                                        ^^^
Because of these parentheses, you're executing the function and assigning its return value rather than assigning a reference to the function itself.[/COLOR]
	}

AHA!

Thanks very much, Jeff!