"Dynamic Table row creation and Deletion"
Bootstrap 3.0.0 Snippet by ricardoard12

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.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"> <script> $(function() { $('input[name=dob]').datepicker(); }); </script> <div class="row clearfix"> <div class="col-md-12 column"> <form method="POST" action='ProdutoController' name="frmAddProd"> <table class="table table-bordered table-hover" id="tab_logic"> <thead> <tr > <th class="text-center"> # </th> <th class="text-center"> Codigo Produto </th> <th class="text-center"> Produto </th> <th class="text-center"> Tipo </th> <th class="text-center"> Data </th> <th class="text-center"> Fabricante </th> </tr> </thead> <tbody> <tr id='addr0'> <td> 1 </td> <td> <input type="text" name='codigo0' placeholder='Codigo' class="form-control"/> </td> <td> <input type="text" name='decricao0' placeholder='Produto' class="form-control"/> </td> <td> <input type="text" name='tipo0' placeholder='Tipo' class="form-control"/> </td> <td> <input type="text" name='data' placeholder='Data' class="form-control"/> </td> <td> <input type="text" name='fabricante0' placeholder='Fabricante' 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><input type="submit" value="Submit" /></form>
$(document).ready(function(){ var i=1; $("#add_row").click(function(){ $('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='id"+i+"' type='text' placeholder='Codigo' class='form-control input-md' /> </td><td><input name='descricao"+i+"' type='text' placeholder='Produto' class='form-control input-md'></td><td><input name='tipo"+i+"' type='text' placeholder='Tipo' class='form-control input-md'></td><td><input name='data"+i+"' type='text' placeholder='Data' class='form-control input-md'></td>><td><input name='fabricante"+i+"' type='text' placeholder='Fabricante' 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: