"Dynamic Table row creation and Deletion"
Bootstrap 3.3.0 Snippet by dfishburn86

<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"> <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"> Quantity </th> <th class="text-center"> Description / Part No. </th> <th class="text-center"> Charge To </th> <th class="text-center"> Price </th> <th class="text-center"> Amount </th> </tr> </thead> <tbody> <tr id='addr0'> <td> <input type="text" name='quantity' placeholder='Quantity' class="form-control"/> </td> <td> <input type="text" name='partno' placeholder='Description / Part No.' class="form-control"/> </td> <td> <input type="text" name='chargeto' placeholder='Charge To' class="form-control"/> </td> <td> <input type="text" name='price' placeholder='Price' class="form-control"/> </td> <td> <input type="text" name='amount' placeholder='Amount' class="form-control"/> </td> </tr> <tr id='addr1'></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(){ $('#addr'+i).html("<td><input name='quantity"+i+"' type='text' placeholder='Quantity' class='form-control input-md' /> </td><td><input name='partno"+i+"' type='text' placeholder='Description / Part No.' class='form-control input-md' /> </td><td><input name='chargeto"+i+"' type='text' placeholder='Charge To' class='form-control input-md' /> </td><td><input name='price"+i+"' type='text' placeholder='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="addr'+(i+1)+'"></tr>'); i++; }); $("#delete_row").click(function(){ if(i>1){ $("#addr"+(i-1)).html(''); i--; } }); });

Related: See More


Questions / Comments: