[thelist] "onchange" event on checkbox and YUI

Bill Moseley moseley at hank.org
Mon Jul 27 17:53:03 CDT 2009


This is the famous IE problem where onchange on a checkbox doesn't
fire until you leave the element.

I have a checkbox and an associated <label>.  When checked I simply
want to display an additional element (additional form elements),
and likewise hide when unchecked.

YAHOO.util.Event.on(
    checkbox_element,
    'change',
    function() { sub_el.style.display = checkbox_element.checked ?
'block' : 'none' }
  );

But, IE won't trigger the event until focus moves from the checkbox.


Keep in mind that the check box can be selected (and de-selected) by
clicking on the label, but also by tabbing to the
checkbox element and hitting the space bar.

I'm wondering if I need an enclosing block to catch multiple events
(change, keyup? ) and limit to events only on the <input> and <label>.

I know this is an old problem so my guess is there's a common solution
I'm missing.

Thanks,










--
Bill Moseley
moseley at hank.org



More information about the thelist mailing list