<script type="text/jscript"> $(document).ready(function() { var table = $("#TextBoxesGroup"); var row = table.find("tr").eq(1); var count = 0; $("#addButton").click(function(e) { if (table.find("tr").length >= 10) { alert("Maximum 10 Item Only"); return; } var newRow = row.clone(); var regex = new RegExp("data\[[0-9]+\]", "g"); newRow.html(newRow.html().replace(regex, "data[" + (++count) + "]")); table.append(newRow); }); $(document).on('keyup', "*[data-field='quantity'],*[data-field='price']", function(e) { var thisRow = $(this).parents("tr:first"); var rowTotalField = thisRow.find("*[data-field='total']"); var price = parseFloat(thisRow.find("*[data-field='price']").val()); var quantity = parseInt(thisRow.find("*[data-field='quantity']").val()); rowTotalField.val("RM" + (!isNaN(price) && !isNaN(quantity) ? price*quantity : 0).toFixed(2)); var total = 0; table.find("*[data-field='total']").each(function() { var t = parseFloat($(this).val().replace("RM", "")); total += !isNaN(t) ? t : 0; }); $("#total").text(total.toFixed(2)); }); }); </script>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)