I’ve got a shopping cart where I need to limit the quantity of certain items. The quantity amount is an input number field.
Using a combination of max and onchange attributes, and the following javascript stops a customers from increasing the amount beyond the limit (15).
function limiter(input) { if (input.value > 15) input.value = 15; };
However, it’s still possible for a customer to add a product to the cart twice (from the product page), with a total quantity that exceeds the limit. As long as they don’t then adjust the quantity input in the cart, it wont be changed back down to 15.
How can I get javascript to check and then limit the input value to 15 when the page loads? (I can apply an ID to the relevant input element to help target it.)
Thanks in advance.
1