Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event for radio button being selected?

Is there some event for a radio button being selected?

I know I can use "click" but I believe it is possible to style radio buttons in some browsers such that clicking an outter area of a radio button might not select the radio button.

What event should I use?

like image 937
Richard Knop Avatar asked Sep 21 '10 14:09

Richard Knop


People also ask

Which event is achieved when a radio button is selected?

You can use the onchange event, which will fire when the radio selection is changed (ie. the first time a radio button in the group is clicked or when the selection within the group is changed).

How can I check if a radio button is selected?

To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.

What is the default event for radio button control?

By default, the control returns a Boolean numeric value to indicate its state (0 for deselected and 1 for selected). However, you can change the return value for a radio button control with the Value property.

How can add click event in radio button?

To define the click event handler for a button, add the android:onClick attribute to the <RadioButton> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.


2 Answers

It depends when you want to be informed of the event.

If you want to know immediately, go with click. IE updates the state of checked before the handler function is called, and I think the other browsers do as well. You may want to double check as I only have IE to work with right now.

If you only need to know before something else happens, you can use change. IE will not fire the change event until the selected radio button loses focus. FF/chrome/others may fire the event without focus changing, but I believe IE is actually doing it right in this case.

like image 152
lincolnk Avatar answered Sep 20 '22 15:09

lincolnk


You can use the onchange event, which will fire when the radio selection is changed (ie. the first time a radio button in the group is clicked or when the selection within the group is changed).

See http://jsfiddle.net/P9Z9Y/1/ for a simple example (clicking on either the label or the radio button itself will trigger an alert if the radio group's value changes).

like image 40
Daniel Vandersluis Avatar answered Sep 17 '22 15:09

Daniel Vandersluis