"Table add row and limited row add "
Bootstrap 3.3.0 Snippet by iammahesh

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <table id="myTable" class=" table order-list"> <thead> <tr> <td>Name</td> <td>Gmail</td> <td>Phone</td> </tr> </thead> <tbody> <tr> <td class="col-sm-4"> <input type="text" name="name" class="form-control" /> </td> <td class="col-sm-4"> <input type="mail" name="mail" class="form-control"/> </td> <td class="col-sm-3"> <input type="text" name="phone" class="form-control"/> </td> <td class="col-sm-2"><a class="deleteRow"></a> </td> </tr> </tbody> <tfoot> <tr> <td colspan="5" style="text-align: left;"> <input type="button" class="btn btn-lg btn-block " id="addrow" value="Add Row" /> </td> </tr> <tr> </tr> </tfoot> </table> </div>
$(document).ready(function () { var counter = 0; $("#addrow").on("click", function () { counter = $('#myTable tr').length - 2; var newRow = $("<tr>"); var cols = ""; cols += '<td><input type="text" class="form-control" name="name' + counter + '"/></td>'; cols += '<td><input type="text" class="form-control" name="mail' + counter + '"/></td>'; cols += '<td><input type="text" class="form-control" name="phone' + counter + '"/></td>'; cols += '<td><input type="button" class="ibtnDel btn btn-md btn-danger " value="Delete"></td>'; newRow.append(cols); if (counter == 4) $('#addrow').attr('disabled', true).prop('value', "You've reached the limit"); $("table.order-list").append(newRow); counter++; }); $("table.order-list").on("change", 'input[name^="price"]', function (event) { calculateRow($(this).closest("tr")); calculateGrandTotal(); }); $("table.order-list").on("click", ".ibtnDel", function (event) { $(this).closest("tr").remove(); calculateGrandTotal(); counter -= 1 $('#addrow').attr('disabled', false).prop('value', "Add Row"); }); }); function calculateRow(row) { var price = +row.find('input[name^="price"]').val(); } function calculateGrandTotal() { var grandTotal = 0; $("table.order-list").find('input[name^="price"]').each(function () { grandTotal += +$(this).val(); }); $("#grandtotal").text(grandTotal.toFixed(2)); }

Related: See More


Questions / Comments: