I would like to clear all radio buttons in a group if I right click on one of them. How can I implement this using Javascript ?
+1
A:
Conceptually you can't unselect radio buttons. The point of a radio button group is that at least one needs to be selected. It could actually be considered a bug that it's possible to have a radio button group in which no item is selected.
I suppose you'd have to remove and re-generate the group to clear the selection, exploiting this "bug".
deceze
2010-04-16 01:49:42
Would the downvoter care to comment?
deceze
2010-04-16 01:53:33
+4
A:
Rather than
Right click an option to deselect: (*) option 1 ( ) option 2 ( ) option 3
which is abusing the user interface, you're better to do this:
( ) none (*) option 1 ( ) option 2 ( ) option 3
Carson Myers
2010-04-16 01:51:33
I don't want to add the "none" option to the interface.The right click option is only for debugging purposes.
Misha Moroshko
2010-04-16 01:54:05
I don't see the value in using this for debugging, there is almost certainly a better way to do whatever it is you want to do.
Carson Myers
2010-04-16 05:52:20
OK,I'll try to explain.I have a form with lots of radio button groups.I have a Javascript code that fills the form randomly. After this is done, I would like to be able to clear all buttons of some groups, then submit the form and check that the validation works fine.
Misha Moroshko
2010-04-18 03:59:45
if you have a form with so many radio button groups that you need a script just to fill it in for you, you might have deeper problems. I don't understand why you can't just submit the form without selecting any of the options, or not allow there to be no selections (in a radio button group, there should always be exactly one selection, no more or less) by selecting one of the options by default.
Carson Myers
2010-04-20 07:33:30
A:
Check out this link at quirksmode on capturing the right mouse click. The combination of an element and a right click should let you uncheck all radio buttons in a given group.
Jarrett Meyer
2010-04-16 01:52:20
@Carson Myers and @deceze both have the correct idea. While it is possible to do, a better question is **should** it be done?
Jarrett Meyer
2010-04-16 01:54:03
Thank you for the link. There is one problem: when I left click on a radio button I can recognize that (display alert message for example), but when I right click on it, Firefox context menu is opened instead. How can I fix this ?
Misha Moroshko
2010-04-16 03:25:32