Reputation: 181
I have a table where all line have a input(type:radio) as an rowid. Ok, in this way I need catch any data of the line where radio is checked. How do I make?
I'm new guy here, so, sorry anything.
Upvotes: 1
Views: 66
Reputation: 46
you could get $('input').prop('checked')
and check which row is selected
Upvotes: 2
Reputation: 3084
you need to refer to the inputs parens, when it changes:
$('input[type=radio]').on('change',function(){
if($(this).prop('checked')){
var $tr = $(this).parents('tr');
$('div').html('selected row is number ' + ($tr.index()) + ', and name is ' + $tr.find('td:last-child').html())
}
});
td{
border:1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td><input name="r" type="radio" value="aaa" /></td>
<td>Jhon</td>
</tr>
<tr>
<td><input name="r" type="radio" value="bbb" /></td>
<td>Sarah</td>
</tr>
</table>
<div></div>
Upvotes: 1