How to get the grand total. Just like the link of the picture below, it only display the amount input and display it beside the other amount. How can I add the grand total.
this is the link of the picture. please click.
grandtotal = 0;
$('input[name^=amount]').each(function() {
//alert($(this).val());
grandtotal += $(this).val();
});
$("#grandtotal").html(grandtotal);
答案 0 :(得分:4)
you're adding strings together, rather than numbers. If you want a number to display, you'll need to use:
//javascript
grandtotal += parseFloat($(this).val());
or, since you added [php] tag:
//php
grandtotal += floatval( $your_variable );