Thursday, June 7, 2012

jquery increase/decrease number in input field

Fiddle Demo - http://jsfiddle.net/dipaks2011/6vuNP/2/

HTML
 <div class="inputQty">
        <span class="up">up</span>         
        <input type="text" maxlength="6" name="oa_quantity" class="input-quantity"  value="1"/> 

        <span class="down">down</span>
</div>

CSS
span{ cursorpointer;}

jQuery
$('.up').on('click',function(){
    $('.input-quantity').val(parseInt($('.input-quantity').val())+1);
});

$('.down').on('click',function(){
    $('.input-quantity').val(parseInt($('.input-quantity').val())-1);
}); 

3 comments:

  1. did you test it? there are many error and it did`t work

    ReplyDelete
    Replies
    1. Yes! The code is tested. Please check the Fiddle demo I have added today :)

      Delete
  2. How to restrict it to 0 and not in minus values?

    ReplyDelete