views:

200

answers:

1

Hi all

This is going to be straight forward for anyone who understands this language.

I have a set of checkboxes, which I am successfully detecting via Javascript on window load.

I now need to detect any change in these checkboxes (ie checked/unchecked) and call in a function to do something else. However using this snippet causes the test function to fire on window load, not onclick, and I don't see why.

//action for county
if (parent != "innerpost") {
county[i].onclick test(name);
}//if  
+3  A: 

You need to write

county[i].onclick = function() { test(name); };
SLaks
For future reference, why do I need to use a function there?
YsoL8
To pass the parameter.
SLaks
A handler (that responds to events) is always a function. So when assigning handlers, you'll always be passing in a function
Juan Mendes