Hi!
I have the following table:
<table>
<tr>
<th>Cost</th>
<th>Quantity</th>
<th>Sum</th>
</tr>
<tr class="txtMult">
<td class="val1">1</td>
<td><input class="val2" type="text" name="txt/>"</td>
<td><span class="sum">0</span>
</tr>
<tr class="txtMult">
<td class="val1">2</td>
<td><input class="val2" type="text" name="txt/>"</td>
<td><span class="sum">0</span>
</tr>
</table>
What i want to do is to multiple row by row cells: val1*val2. I found the solution, which is working only if value in class val1 is an input value :(. I tried to change value in class val1 to float but it didnt work - as total it displays NaN. Thx for help.
$(document).ready(function(){
$(".txtMult input").keyup(multInputs);
function multInputs() {
var mult = 0;
$("tr.txtMult").each(function () {
var $val1=parseFloat($('.val1', this).val());
var $val2=parseFloat($('.val2', this).val());
var $total = ($val1 * 1) * ($val2 * 1)
$('.sum',this).text($total);
mult += $total;
});
});