"Input Spinner with min and max values"
Bootstrap 3.3.0 Snippet by bryanrojasq

<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="page-header"> <h1>Bootstrap 3 input-spinner</h1> <h2>With Min & Max Values Limited</h2> </div> <div class="col-md-4"> <div class="input-group spinner"> <input type="text" class="form-control" value="1" min="0" max="5"> <div class="input-group-btn-vertical"> <button class="btn btn-default" type="button"><i class="fa fa-caret-up"></i></button> <button class="btn btn-default" type="button"><i class="fa fa-caret-down"></i></button> </div> </div> <p class="help-block">Min 0 - Max 5.</p> </div> <div class="col-md-4"> <div class="input-group spinner"> <input type="text" class="form-control" value="42" min="40" max="45"> <div class="input-group-btn-vertical"> <button class="btn btn-default" type="button"><i class="fa fa-caret-up"></i></button> <button class="btn btn-default" type="button"><i class="fa fa-caret-down"></i></button> </div> </div> <p class="help-block">Min 40 - Max 45.</p> </div> <div class="col-md-4"> <div class="input-group spinner"> <input type="text" class="form-control" value="10" min="5" max="15"> <div class="input-group-btn-vertical"> <button class="btn btn-default" type="button"><i class="fa fa-caret-up"></i></button> <button class="btn btn-default" type="button"><i class="fa fa-caret-down"></i></button> </div> </div> <p class="help-block">Min 5 - Max 15.</p> </div> <div class="col-md-12"> <div class="alert alert-info"> <p>Based on the best features of this 2 snippets:</p> <a href="http://codepen.io/Thomas-Lebeau/pen/csHqx" target="_blank">http://codepen.io/Thomas-Lebeau/pen/csHqx</a> <br> <a href="http://bootsnipp.com/snippets/featured/bootstrap-number-spinner-on-click-hold" target="_blank">http://bootsnipp.com/snippets/featured/bootstrap-number-spinner-on-click-hold</a> </div> </div> </div>
@import url(http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css); .spinner input { text-align: right; } .input-group-btn-vertical { position: relative; white-space: nowrap; width: 2%; vertical-align: middle; display: table-cell; } .input-group-btn-vertical > .btn { display: block; float: none; width: 100%; max-width: 100%; padding: 8px; margin-left: -1px; position: relative; border-radius: 0; } .input-group-btn-vertical > .btn:first-child { border-top-right-radius: 4px; } .input-group-btn-vertical > .btn:last-child { margin-top: -2px; border-bottom-right-radius: 4px; } .input-group-btn-vertical i { position: absolute; top: 0; left: 4px; }
$(function(){ $('.spinner .btn:first-of-type').on('click', function() { var btn = $(this); var input = btn.closest('.spinner').find('input'); if (input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max'))) { input.val(parseInt(input.val(), 10) + 1); } else { btn.next("disabled", true); } }); $('.spinner .btn:last-of-type').on('click', function() { var btn = $(this); var input = btn.closest('.spinner').find('input'); if (input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min'))) { input.val(parseInt(input.val(), 10) - 1); } else { btn.prev("disabled", true); } }); })

Related: See More


Questions / Comments: