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

<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"> <!-- panel preview --> <div class="col-sm-5"> <h4>Vehículos de la Orden:</h4> <div class="panel panel-default"> <div class="panel-body form-horizontal payment-form"> <div class="form-group"> <label for="concept" class="col-sm-3 control-label">Tipo de Vehículo</label> <div class="col-sm-9"> <select class="form-control" id="vehiculo" name="vehiculo"> <option>Plataforma 8000</option> <option>Plataforma 10000</option> <option>Furgón 6000</option> <option>Furgón 7000</option> <option>Furgón 10000</option> <option>Lancha</option> <option>Gabarra</option> </select> </div> </div> <div class="form-group"> <label for="amount" class="col-sm-3 control-label">Cantidad</label> <div class="col-sm-9"> <input type="number" class="form-control" id="cantidadV" name="cantidadV"> </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> Agregar </button> </div> </div> </div> </div> </div> <!-- / panel preview --> <div class="col-sm-7"> <h4>Detalle:</h4> <div class="row"> <div class="col-xs-12"> <div class="table-responsive"> <table class="table preview-table"> <thead> <tr> <th>Tipo de Vehículo</th> <th>Cantidad</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 class="row"> <div class="col-xs-12"> <hr style="border:1px dashed #dddddd;"> <button type="button" class="btn btn-primary btn-block">Submit all and finish</button> </div> </div> </div> </div> </div>
function calc_totalV(){ var sum = 0; $('.input-cantidadV').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_totalV() }); }); $(function(){ $('.preview-add-button').click(function(){ var form_data = {}; form_data["vehiculo"] = $('.payment-form #vehiculo option:selected').text(); form_data["cantidadV"] = parseFloat($('.payment-form input[name="cantidadV"]').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_totalV(); }); });

Related: See More


Questions / Comments: