Advertisement
Advertisement


Get group radio button selected value via jquery


Question

How can I get the selected radio button value via jQuery? I tried:

var selectedPlan = $("input[name=Plan[packageId]]:checked'").val();
alert(selectedPlan);

bBt didn't work.

<td style="vertical-align: top;">
    <input type="radio" value="1" name="Plan[packageId]">
    <lable>3 Games</lable><br>

    <input type="radio" value="2" name="Plan[packageId]">
    <lable>5 Games</lable><br>

    <input type="radio" value="3" name="Plan[packageId]">
    <lable>10 Games</lable><br>
</td>

here is the fiddle http://jsfiddle.net/vk3z45an/

2015/05/21
1
-1
5/21/2015 7:11:23 AM

Accepted Answer

You need to escape the CSS meta characters or wrap them in quote for preventing the selector from breaking:

var selectedPlan = $("input[name='Plan[packageId]']:checked").val();

Working Demo

2015/05/21
2
5/21/2015 7:11:48 AM