I am calculating totals when a particular check boxes are being checked. The code is working fine. How can i view the grandtotal of all the item values if none of the checkboxes are checked.?
$(function () {
$("input[type='checkbox'").on("click", function () {
recalcTotal();
});
function recalcTotal() {
var total = 0;
$("input:checked").each(function () {
total += $(this).next("input").val() * 1;
});
$("#total").val(total);
}
});
<input type="checkbox" name="values"/><input type="text" readonly value="100"/> <br />
<input type="checkbox" name="values" /><input type="text" readonly value="200"/> <br />
<input type="checkbox" name="values" /><input type="text" readonly value="300"/> <br />
<input type="checkbox" name="values" /><input type="text" readonly value="400"/> <br />
<input type="checkbox" name="values" /><input type="text" readonly value="500"/> <br />
<input type="checkbox" name="values" /><input type="text" readonly value="600"/> <br /><br />
<b>Grand Total:</b> <input type="text" id="total" readonly/> <br />
How can i view the grandtotal of all the item values if none of the checkboxes are checked.?