"Quantity increment buttons"
Bootstrap 3.3.0 Snippet by naseemfasal

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.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"> <h2>Simple Quantity increment buttons with Javascript </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: