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

<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-10 column"> <table class="table table-bordered table-hover" id="tab_service"> <thead> <tr > <th class="text-center"> ลำดับ </th> <th class="text-center"> รายการ </th> <th class="text-center"> หน่วย </th> <th class="text-center"> ราคา </th> </tr> </thead> <tbody> <tr id='addr0'> <td> <center>1</center> </td> <td> <input type="text" name='name0' placeholder='รายการ' class="form-control"/> </td> <td> <input type="text" name='mail0' placeholder='หน่วย' class="form-control"/> </td> <td> <input type="text" name='mobile0' placeholder='ราคา' class="form-control"/> </td> </tr> <tr id='addr1'></tr> </tbody> </table> <div class="form-group"> <a id="add_row" class="btn btn-default pull-left">เพิ่มรายการ</a> <a id='delete_row' class="pull-right btn btn-default">ลบรายการ</a> </div> </div> </div> </div>
$(document).ready(function(){ var i=1; $("#add_row").click(function(){ $('#addr'+i).html("<td><center>"+ (i+1) +"</center></td><td><input name='name"+i+"' type='text' placeholder='รายการ' class='form-control input-md' /> </td><td><input name='mail"+i+"' type='text' placeholder='หน่วย' class='form-control input-md'></td><td><input name='mobile"+i+"' type='text' placeholder='ราคา' class='form-control input-md'></td>"); $('#tab_service').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: