How to get the value of th with input in html? My problem in the fifth th, it won't get the value of the input. See my javascript code. Anyone knows the idea of solving this problem? This code is fine but when I add input field inside th, it's not working. What did i miss here? Is there a possible way to achieve my goal? Note: I just need the input in the fifth th.
<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 = parseInt($(this).html());
total += number;
ave = total/count;
count++;
});
$(this).children('th').last().html(ave);
});
</script>