views:

46

answers:

5

Hello,

I'm trying to get the ID value of the set of radio buttons. Here is the radio buttons.

<input id="1" type="radio" title="2" value="6/1/2010" name="vacationDay">
<input id="2" type="radio" title="2" value="6/2/2010" name="vacationDay">
<input id="3" type="radio" title="2" value="6/3/2010" name="vacationDay" checked='checked'>

Here is my script.

var updateDay = $('input[name=vacationDay]:checked').val();

It returns the value (6/3/2010) of the selected radio button just fine. I would like to get the id (3) as well. Thank you in advance for your help!

+4  A: 
var $radio = $('input[name=vacationDay]:checked');
var updateDay = $radio.val();
var id = $radio.attr('id');

.attr()

Dan Heberden
Thanks Dan, that worked like a charm!
+2  A: 
   var btnId = $('input[name=vacationDay]:checked').attr('id');
womp
+2  A: 

not sure if this is what you wish for :

var id = $('input[name=vacationDay]:checked').attr('id');
Puaka
+1  A: 

You can change your .val() to .attr('id')!

var updateDay = $('input[name=vacationDay]:checked').attr('id');​
EndangeredMassa
A: 

try

var updateDay = $('input[name=vacationDay]:checked').attr('id')

naiquevin