Cart Quantity plus and minus buttons on the shopping cart default page. Is this possible?
I am trying to add a basic jquery script that will add a plus and minus to the quantity box on the cart page. For some reason I cant get it to work correctly. The input value always go back to 1 as indicated var n = 1; //n is equal to 1. How would I get that to make it so it put the correct value in there.
includes\modules\pages\shopping_cart\header_php.php. This is the piece of code i edited... If someone can assist me or lead me in the right direction I would greatly appreciate it.
Code:
$quantityField = '<span class="plus button">+' .'</span>' . zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4" name="qty" id="qty" class="cart_input_'.$products[$i]['id'].' "'). '<span class="min button">-
</span>';
Simple jquery script
Code:
<script>jQuery(function(){
var j = jQuery; //Just a variable for using jQuery without conflicts
var addInput = '$products[$i]['quantity']'; //This is the id of the input you are changing
var n = 1; //n is equal to 1
//Set default value to n (n = 1)
j(addInput).val(n);
//On click add 1 to n
j('.plus').on('click', function(){
j(addInput).val(++n);
})
j('.min').on('click', function(){
//If n is bigger or equal to 1 subtract 1 from n
if (n >= 1) {
j(addInput).val(--n);
} else {
//Otherwise do nothing
}
});
});</script>
Bookmarks