Neeraj
Neeraj

Reputation: 9145

how to get radio button value using jquery

<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

Answers (3)

karthick
karthick

Reputation: 9

$("input:radio[name=theme]").click(function() {
    var value = $(this).val();
});

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

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

A. Wolff
A. Wolff

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

Related Questions