pipomenace pipomenace -4 years ago 146
Javascript Question

Javascript Increment by more than 1?

Here's my script :

//event handler for item quantity in shopping cart
function itemQuantityHandler(p, a) {
//get current quantity from cart
var filter = /(\w+)::(\w+)/.exec(p.id);
var cart_item = cart[filter[1]][filter[2]];
var v = cart_item.quantity;

//add one
if (a.indexOf('add') != -1) {
if(v < settings.productBuyLimit) v++;
//substract one
if (a.indexOf('subtract') != -1) {
if (v > 1) v--;

//update quantity in shopping cart
//save new quantity to cart
cart_item.quantity = v;
//update price for item
//update total counters

What I need is to increase "v" (cart_item.quantity) by more than one. Here, it's using "v++"...but it's only increasing by 1. How can I change this to make it increase by 4 everytime I click on the plus icon?

I tried

v++ +4

But it's not working.

Thank you!

Answer Source

Use a compound assignment operator:

v += 4;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download