"Dynamic Table row creation and Deletion v.Rixki c.02 [total currently not working]"
Bootstrap 3.0.3 Snippet by rixki

<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"> Value1 </th> <th class="text-center"> Value2 </th> <th class="text-center"> Select </th> </tr> </thead> <tbody> <tr id='addr0'> <td> 1 </td> <td> <input type="text" name='va10' placeholder='Val1' class="form-control"/> </td> <td> <input type="text" name='va20' placeholder='Val2' class="form-control"/> </td> <td class="optx"> <select class="form-control sltx" name="slct0" placeholder="Select"><option value="1">1</option><option value="2">2</option></select> </td> </tr> <tr id='addr1'></tr> </tbody> <tfoot> <tr> <th></th> <th></th> <th><a id="buttonx" class="btn btn-default btn-danger pull-right">Calculate</a></th> <th id="totality" style="vertical-align: middle;">Total : </th> </tr> </tfoot> </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>"+ (i+1) +"</td><td><input name='name"+i+"' type='text' placeholder='Name' class='form-control input-md' /> </td><td><input name='mail"+i+"' type='text' placeholder='Mail' class='form-control input-md'></td><td><select class='form-control' name='slct"+i+"' placeholder='Select'><option value='1'>1</option><option value='2'>2</option></select></td>"); $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>'); i++; }); $("#delete_row").click(function(){ if(i>1){ $("#addr"+(i-1)).html(''); i--; } }); }); $('.buttonx').click(function() { var total = 0; $('#tab_logic tbody tr').each(function(index) { var price = parseInt($(this).find('.optx sltx option value').text()); var quantity = parseInt($(this).find('.optx sltx option').val()); var value = $(this).find('.value'); var subTotal = price * quantity; value.text(subTotal); value.text(price); total = total + subTotal; testotal = price; }); $('.totality').text('Total : '+testotal); });

Related: See More


Questions / Comments: