JQuery: get the value of the selected radio group when the name is an array?

I have a group of radio groups, as shown below, and I'm having trouble getting the selected / checked value. I think this is because the name is an array. I renamed my id to the same to see if I can do it this way, but no luck.

<input type="radio" name="accounts[1][details][status]" value="1" id="status_1" />
<input type="radio" name="accounts[1][details][status]" value="2" id="status_1" />

thank

+3
source share
2 answers

That should do it. See jQuery docs for escaping special characters .

$('input[name="accounts\\[1\\]\\[details\\]\\[status\\]"]:checked').val();
+5
source

You are looking for: checked to select the one that is selected

<input type="radio" name="accounts[1][details][status]" value="1" class="status" />
<input type="radio" name="accounts[1][details][status]" value="2" class="status" />

jQuery: 

$(".status").change(function ()
{
    var checked_value = $(".status:checked").val();
});
+4
source

All Articles