Hi Rajnish,
I have done few modification to the code. Now checking for NaN or parsing not required as the textbox wont allow non-numeric characters.
Also added blur event to the quantity textbox such that tab out keys will be supported.
$(document).ready(function () {
$(function () {
$("[id*=txtQuantity],[id*=lblTotal],[id*=lblGrandTotal]").val("0");
});
$("[id *= txtQuantity]").keypress(function (e) {
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
$("[id*=txtQuantity]").on("keyup blur", function () {
var row = $(this).closest("tr");
$("[id*=lblTotal]", row).html(parseFloat($(".price", row).html()) * parseFloat(jQuery.trim($(this).val()) == '' ? 0 : $(this).val()));
var grandTotal = 0;
$("[id*=lblTotal]").each(function () {
grandTotal = grandTotal + parseFloat($(this).html());
});
$("[id*=lblGrandTotal]").html(grandTotal.toString());
});
});
Thanks
Srikant