Reputation: 9145
<input id="user_type_local" type="radio" checked="true" value="local" name="data[user_type]">
Local
<input id="user_type_sso" type="radio" value="sso" name="data[user_type]">
Gilead SSO
How can we get the value of checked radio button using jQuery? I tried
$('input[name=data[user_type]]:radio').val();
But it does not work.
Error: Syntax error, unrecognized expression: input[name=data[user_type]]:radio
Upvotes: 1
Views: 12977
Reputation: 9
$("input:radio[name=theme]").click(function() {
var value = $(this).val();
});
Upvotes: 0
Reputation: 67187
[
and ]
are meta-characters, you have to escape it, or you can simply make that as a string.
Try,
$('input[name="data[user_type]"][type="radio"]').val();
Upvotes: 3
Reputation: 74420
You should wrap string in quotes:
$('input[name="data[user_type]"]:radio').val();
Which is the same as using double escape:
$('input[name=data\\[user_type\\]]:radio').val();
Upvotes: 4