I have a problem in targetting the last th tag.In the fifth th, i put input type text.How to add event in this text field and the value of the last th(ave) should be updated automatically?Any help here is much appreciated.
<tr>
<th colspan="3">Learning Areas</th>
<th colspan="2">Term 1</th>
<th colspan="2">Term 2</th>
<th colspan="2">Term 3</th>
<th colspan="2">Term 4</th>
<th>Ave</th>
</tr>
</thead>
<tbody>
@foreach($card['AllGrade'] as $subject)
{!! Form::hidden('grade_id[]',$subject['grade_id']) !!}
<tr>
<th colspan="3">{!! $subject->subject !!}</th>
<th colspan="2">{!! $subject->term_1 !!}</th>
<th colspan="2">{!! $subject->term_2 !!}</th>
<th colspan="2">{!! $subject->term_3 !!}</th>
<th colspan="2"><input text="term_4" value="{!! $subject->term_4 !!}"
class="form-control" name="term_4"></th>
<th colspan="2" name ="ave" id ="ave" value=""> total</th>
</tr>
@endforeach
<script type="text/javascript">
$("tbody tr").each(function() {
var total = 0;
var ave = 0;
var count = 1;
$(this).children('th').not(':first').not(':last').each(function () {
//"this" is the current element in the loop
var number = ($(this).children('input').length == 0) ? $(this).html() :
$(this).children('input').first().val();
total += parseInt(number);
ave = total/count;
count++;
});
$(this).children('th').last().html(ave);
});
</script>
htmlat Question?