0
I have this script he goes through the table and picks up the values. But it would be more restrictive taking only the line that triggered the event.
$(document).ready(function(){
$(document).on('change','table tbody tr td input',function(){
var v = 0;
$('input').each(function(i,e) {
if(i > 8)
{
return true;
}
if(i !== 2)
{
if ($(e).val())
{
var i = $(e).val().replace(/\,/g,'.');
if (isNaN(i)) { $(e).val(''); return; }
v += parseFloat(i);
$('.total').val( v.toFixed(2));
}
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<thead>
<th>
VALOR 1
</th>
<th>
VALOR 2
</th>
<th>
TOTAL
</th>
</thead>
<tbody>
<tr>
<td>
<input type='text' name='name0' placeholder='' class='form-control'/>
</td>
<td>
<input type='text' name='name0' placeholder='' class='form-control'/>
</td>
<td>
<input type='text' name='name0' placeholder='' class='form-control total' disabled/>
</td>
</tr>
<tr>
<td>
<input type='text' name='name0' placeholder='' class='form-control'/>
</td>
<td>
<input type='text' name='name0' placeholder='' class='form-control'/>
</td>
<td>
<input type='text' name='name0' placeholder='' class='form-control total' disabled/>
</td>
</tr>
</tbody>
</table>
You can use
$(this).closest('tr').find('input'). each etc
in time of$('input'). each
. That’s what you’re looking for?– Sergio