Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31357
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Intercept radio onclick event |
| Date | 2016-09-13 16:58 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1624351.tdWV9SEqCh@PointedEars.de> (permalink) |
| References | <nr6ja2$dqc$1@dont-email.me> <nr8u8i$6na$1@dont-email.me> <nr8var$1e8$1@solani.org> |
Christoph M. Becker wrote: > On 13.09.2016 at 15:17, wmgill wrote: >> On 9/12/2016 11:58 AM, wmgill wrote: >>> Is there a way to intercept a radio button onclick event and pass it >>> through a confirmation process before allowing it to proceed or >>> cancelling it? I have found several solutions that propose to do this, >>> but in fact they just set or reset the radio's checked property, which >>> doesn't reset any other radio button in the group to original state. >> I seem to be catching the onclick event, but not early enough in the >> process. So I still need some help in a couple areas. >> >> Any insights as to what is going on, and how to correct it? > > Have you considered to use the change event instead of a the click > event? See > <https://developer.mozilla.org/en-US/docs/Web/Events/change>, for > instance. The “click” event is specified to be fired when a pointing device’s state has changed from “button pushed” (“mousedown” event)/“finger touching” (“touchstart” event)/“pen down” (“pointerdown” event) and back to “button released” (mouseup)/“finger not touching” (touchend)/“pen up” (“pointerup” event) while on the same target. IOW: mousedown → … → mouseup → click (if same target); touchstart → … → touchend → click (if same target); pointerdown → … → pointerup → click (if same target). The “change” event is specified to be fired when a control’s value has been changed by the user and it has just lost focus: focusin → … → focusout → change (if value changed by user). So canceling either on a radiobutton is not likely to prevent it from being checked. In Chromium 53 on GNU/Linux it does not, although the “change” event is already fired when the radiobutton is checked (interestingly, not when another radiobutton in the same group is checked, i.e. the target’s “checked” state changes from “checked” to “unchecked”). To see what is going on, use the browser’s developer tools. One could additionally cancel events such as “mousedown”, “touchstart”, and “pointerdown” – this does not work with radiobuttons in that Chromium version, only canceling “click” works there –, but why not simply set the “disabled” attribute/property of the radiobutton (to “true”)? As an alternative, the “defaultChecked” property value of each radiobutton of the group could be used, but reverting user’s choices immediately really is not user-friendly and might be prevented by browser vendors in the future (they already did so with disabling this.focus() on “blur”). See also <https://developer.mozilla.org/en-US/docs/Web/Events> pp. (AFAIK, the best event reference there is; I am pleased to see how far it and the events landscape has evolved since I made my initial contribution.) -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Intercept radio onclick event wmgill <webworker1950@gmail.com> - 2016-09-12 11:58 -0400
Re: Intercept radio onclick event wmgill <webworker1950@gmail.com> - 2016-09-13 09:17 -0400
Re: Intercept radio onclick event "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-09-13 15:35 +0200
Re: Intercept radio onclick event wmgill <webworker1950@gmail.com> - 2016-09-13 10:27 -0400
Re: Intercept radio onclick event Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-13 16:58 +0200
Intercept radio onclick event Ram Tobolski <ramtob@gmail.com> - 2016-09-13 11:38 -0700
Re: Intercept radio onclick event wmgill <webworker1950@gmail.com> - 2016-09-13 15:53 -0400
csiph-web