Wednesday, January 6, 2010

Get the value of selected radio button

In prototype you can use the following code to get the value of selected radio button in a group of radio button.

If you have only one group of radio button in page then use the following code

$$('input[type=radio]:checked').pluck('value');


If you have more than one group of radio button then use following code


$$('input:checked[type="radio"][name="my_radio_group"]').pluck('value');

$$ will get the element input (html tag) which is checked and whose type is radio with name my_radio_group and pluck the value attribute.

It will help you a lot.


Followers