Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ID value from set of radio buttons

I'm trying to get the id of the set of radio buttons. Here is the HTML for it.

<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 Javascript.

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

It returns the value (6/3/2010) of the selected radio button . I would like to get the id of the checked button (3) as well. Ideas?

like image 729
user281867 Avatar asked Nov 29 '22 19:11

user281867


1 Answers

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

.attr()

like image 120
Dan Heberden Avatar answered Dec 05 '22 16:12

Dan Heberden