Reputation: 267287
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.
Upvotes: 0
Views: 167
Reputation: 196236
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
Upvotes: 4