"Payment form with total preview"
Bootstrap 3.1.0 Snippet by detain

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.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"> <div class="col-sm-12"> <legend>Filiais:</legend> </div> <!-- panel preview --> <div class="col-sm-5"> <h4>Adicione Filial:</h4> <div class="panel-body form-horizontal payment-form"> <div class="form-group"> <label for="status" class="col-sm-3 control-label">Status</label> <div class="col-sm-9"> <select class="form-control" id="status" name="status"> <option>Selecione: </option> <option>Filial 0101 - Matriz</option> <option>Filial 0102 - Recife</option> <option>Filial 0103 - Olindina</option> <option>Filial 0104 - Abaetetuba</option> </select> </div> </div> <div class="form-group"> <div class="col-sm-12 text-right"> <button type="button" class="btn btn-default preview-add-button"> <span class="glyphicon glyphicon-plus"></span> Add </button> </div> </div> </div> </div> <!-- / panel preview --> <div class="col-sm-7"> <h4>Preview:</h4> <div class="row"> <div class="col-xs-12"> <div class="table-responsive"> <table class="table preview-table"> <thead> <tr> <th>Filiais</th> </tr> </thead> <tbody></tbody> <!-- preview content goes here--> </table> </div> </div> </div> <div class="row text-right"> <div class="col-xs-12"> <h4>Total: <strong><span class="preview-total"></span></strong></h4> </div> </div> </div> </div> </div>
function calc_total(){ var sum = 0; $('.input-amount').each(function(){ sum += parseFloat($(this).text()); }); $(".preview-total").text(sum); } $(document).on('click', '.input-remove-row', function(){ var tr = $(this).closest('tr'); tr.fadeOut(200, function(){ tr.remove(); calc_total() }); }); $(function(){ $('.preview-add-button').click(function(){ var form_data = {}; form_data["concept"] = $('.payment-form input[name="concept"]').val(); form_data["description"] = $('.payment-form input[name="description"]').val(); form_data["amount"] = parseFloat($('.payment-form input[name="amount"]').val()).toFixed(2); form_data["status"] = $('.payment-form #status option:selected').text(); form_data["date"] = $('.payment-form input[name="date"]').val(); form_data["remove-row"] = '<span class="glyphicon glyphicon-remove"></span>'; var row = $('<tr></tr>'); $.each(form_data, function( type, value ) { $('<td class="input-'+type+'"></td>').html(value).appendTo(row); }); $('.preview-table > tbody:last').append(row); calc_total(); }); });

Related: See More


Questions / Comments: