If I have a few checkboxes like the following:
<input type="checkbox" onchange="foo(bar);" /> Bar
Will the foo(bar); function only be called when the checkbox is checked on/off by a click or keypress (what I want) or if I progromatically check/uncheck a lot of checkboxes with a select/unselect alll button, will it then call the onchange function for all of the checkboxes (what I don’t want)?
And will all browsers have the same behavior?
Internet Explorer (at least the old ones) doesn’t fire the “change” event until the checkbox loses focus. Try using “onclick” instead.
The callback won’t be called if your code changes the “checked” status ([edit] except in cases as described by Mr. Bouman’s answer)