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);
});