Julio Cesar Boaroli
Julio Cesar Boaroli

Reputation: 181

Get data from line where input radio is checked

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

Answers (2)

Snunit
Snunit

Reputation: 46

you could get $('input').prop('checked') and check which row is selected

Upvotes: 2

MoLow
MoLow

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

Related Questions