1

I currently have a quantity input in the works that lets the user type in a number, but I'd also like it if there were an option next to the input that lets them click a "+" sign to add onto the quantity. How do I do this?

Like this sites quantity option: http://www.nastygal.com/clothes-tops-graphics/going-batty-muscle-tee

My quantity input code:

QTY:</b> {{ product | product_quantity_input }}
RegTX
  • 17
  • 2
kdm
  • 35
  • 1
  • 2
  • 9

1 Answers1

0
//initialize the input to 1
$(".quantity").val("1");

//when clicking the plus button, add one
$(".plus-btn").click(function(){
    //get the current value and convert it to an integer
    var currVal = parseInt($(".quantity").val(), 10);
    //set the incremented value 
    $(".quantity").val(currVal+1);
});

//when clicking the minus button, subtract one
$(".minus-btn").click(function(){
    //get the current value and convert it to an integer
    var currVal = parseInt($(".quantity").val(), 10);
    //set the decremented value if its not less than 1
    if(currVal > 1){
        $(".quantity").val(currVal-1);
    }
});

See example: http://jsfiddle.net/ES89t/

Sam Battat
  • 5,725
  • 1
  • 20
  • 29