Nothing works fine. I want the subTotal field to show the calculated amount when I change the quantity. I'm relatively new to web development and programming. Thanks in advance.
HTML
<tr>
<td><input id="quantity" type="text" name="name" value="<?php echo $row['name'] ?>" readonly="readonly"></td>
<td><input id="quantity-sm" type="text" name="price" class="price" value="<?php echo $row['price'] ?>" ></td>
<td>
<input type="button" value="-" class="qtyminus" field="quantity">
<input type="submit" name="quantity" class="quantity" value="0" class="qty">
<input type="button" value="+" class="qtyplus" field="quantity">
</td>
<td><input id="quantity-sm" type="text" class="subTotal" name="subTotal" ></td></td>
</tr>
<?php endwhile; ?>
<tfoot>
<tr><td colspan="2"></td><td align="right"><span id="total" class="total"></span> </td></tr>
</tfoot>
JQuery
$(document).ready(function(){
update_amounts();
$('.qty').change(function() {
update_amounts();
});
});
function update_amounts()
{
var sum = 0.0;
$('#myTable > tbody > tr').each(function() {
var qty = $(this).find('.quantity').val();
var price = $(this).find('.price').val();
var amount = (qty*price)
sum+=amount;
$(this).find('.subTotal').text(''+amount);
});
$('.total').text(sum);
}