0

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  

1 Answer 1

4

You need to write

county[i].onclick = function() { test(name); };
Sign up to request clarification or add additional context in comments.

2 Comments

For future reference, why do I need to use a function there?
A handler (that responds to events) is always a function. So when assigning handlers, you'll always be passing in a function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.