Rahul Singh
Rahul Singh

Reputation: 1632

Radio button group retrieve value

I have group radio buttons with same name cost and different id's cost_1, cost_2. and their values are also different. I wish to collect value of selected radio button. and show it in particular text box that is 'total' including values of other radio button group. How can I get value of selected radio button from name using jQuery? Because if I select it using ID and loop it will count value of each radio button.

Upvotes: 1

Views: 306

Answers (1)

mgibsonbr
mgibsonbr

Reputation: 22007

You could filter for the name and the checked status:

$('input[type="radio"][name="cost"]:checked').val()

Edit: got the selector wrong, now it should work.

Upvotes: 1

Related Questions