[Javascript] onclick and functions
David Dorward
david at dorward.me.uk
Sat Aug 12 09:35:28 CDT 2006
tedd wrote:
> a.onclick = test1(1);
> b.onclick = test2();
> 1. Why do the alerts show at start-up?
>
> 2. Why does the onclick not work (i.e., no alerts)?
Since you are calling the function immediately and then assigning the
return value from the function to the onclick property. You need to
assign a function to it.
a.onclick = function () { test1(1); }
More information about the Javascript
mailing list