"Dynamic Table row creation and Deletion"
Bootstrap 3.0.3 Snippet by ghouse432

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/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"> <div class="row clearfix"> <div class="col-md-12 column"> <table class="table table-bordered table-hover" id="tab_logic"> <thead> <tr > <th class="text-center"> # </th> <th class="text-center"> Barcode </th> <th class="text-center"> Quantiry </th> <th class="text-center"> MRP Price </th> <th class="text-center"> Discounted Price </th> <th class="text-center"> Amount </th> </tr> </thead> <tbody> <tr id='item0'> <td> 1 </td> <td> <input type="text" name='barcode0' placeholder='Barcode' class="form-control"/> </td> <td> <input type="text" name='qty0' placeholder='Quantity' class="form-control"/> </td> <td> <input type="text" name='mrp0' placeholder='MRP Price' class="form-control"/> </td> <td> <input type="text" name='disc_price0' placeholder='Discount Price' class="form-control"/> </td> <td> <input type="text" name='amount0' placeholder='Amount' class="form-control"/> </td> </tr> <tr id='item1'></tr> <!--<tr id='total0'> <th scope="row">11</th> <td colspan="4" >Total Amount</td> <td><input type="text" name='total0' placeholder='Total Amount' class="form-control"/></td> </tr>--> </tbody> </table> </div> </div> <a id="add_row" class="btn btn-default pull-left">Add Row</a><a id='delete_row' class="pull-right btn btn-default">Delete Row</a> </div>
$(document).ready(function(){ var i=1; $("#add_row").click(function(){ $('#item'+i).html("<td>"+ (i+1) +"</td><td><input name='barcode"+i+"' type='text' placeholder='Barcode' class='form-control input-md' /> </td><td><input name='qty"+i+"' type='text' placeholder='Quantity' class='form-control input-md'></td><td><input name='mrp"+i+"' type='text' placeholder='MRP Price' class='form-control input-md'></td><td><input name='disc_price"+i+"' type='text' placeholder='Discount Price' class='form-control input-md'></td><td><input name='amount"+i+"' type='text' placeholder='Amount' class='form-control input-md'></td>"); $('#tab_logic').append('<tr id="item'+(i+1)+'"></tr>'); i++; }); $("#delete_row").click(function(){ if(i>1){ $("#item"+(i-1)).html(''); i--; } }); });

Related: See More


Questions / Comments: