"calc"
Bootstrap 4.0.0 Snippet by Rajeshreeputra

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2>Quantity increment buttons</h2> <div class="col-lg-2"> <div class="input-group"> <span class="input-group-btn"> <button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field=""> <span class="glyphicon glyphicon-minus"></span> </button> </span> <input type="text" id="quantity" name="quantity" class="form-control input-number" value="10" min="1" max="100"> <span class="input-group-btn"> <button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field=""> <span class="glyphicon glyphicon-plus"></span> </button> </span> </div> </div> </div> </div>
$(document).ready(function(){ var quantitiy=0; $('.quantity-right-plus').click(function(e){ // Stop acting like a button e.preventDefault(); // Get the field name var quantity = parseInt($('#quantity').val()); // If is not undefined $('#quantity').val(quantity + 1); // Increment }); $('.quantity-left-minus').click(function(e){ // Stop acting like a button e.preventDefault(); // Get the field name var quantity = parseInt($('#quantity').val()); // If is not undefined // Increment if(quantity>0){ $('#quantity').val(quantity - 1); } }); });

Related: See More


Questions / Comments: