• 0

what's the Standard way of handling checkbox changes with Javascript?


Question

From the W3C documents, it seems the onchange event should only fire after the control loses its focus AND the state is changed, strangely for checkboxes, only IE does that, while browsers like Opera, Safari and Firefox fires the onchange event as soon as the checkbox state is changed, even when the focus is still on the checkbox. I'm not sure if it means IE follows the W3C standards better than Opera, Safari and Firefox in this particular case or what, but anyway it doesn't look like onchange is the standards-compliant way of handling checkbox state the moment it changes.

For the onclick event, the W3C says that it should fire before the HTML action takes place, but notes that for checkboxes, some implementations fires the onclick event after the checkbox state is changed. Turns out all the implementations out there I know of (IE, Opera, Safari and Firefox) fires the onclick event after the checkbox state is changed, so using onclick does provide a cross-browser way of handling checkbox changes, but it doesn't look like it's what W3C recommends to do. By the wording of the W3C recommendation, it seems that a standards compliant browser can (and maybe should) fire the onclick event BEFORE the checkbox state is changed.

So I'm wondering what is the standards-compliant way of handling checkbox changes with Javascript? Thanks.

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.