views:

30

answers:

1

If I have the following radios:

<input name="color" id="color_blue" value="blue">Blue
<input name="color" id="color_red" value="red">Red
<input name="color" id="color_green" value="blue">Green

What's the easiest way to find out which radio the user selected? Preferably something like to:

$("color").val();

Or something close to that.

+3  A: 

The answer is

$('input[name="color"]:checked').val()​​​​​​​​​​​​​​​;

but you have some errors in your html (in the question at least).. (no type="radio" specified..)

<input type="radio" name="color" id="color_blue" value="blue">Blue
<input type="radio" name="color" id="color_red" value="red">Red
<input type="radio" name="color" id="color_green" value="blue">Green
Gaby
Gaby is right. I mistakenly substituted 'selected' for 'checked'.
patrick dw
cheers mate .. .
Click Upvote