Sending JQuery rendered integers to cart as Quantity Values

Solved
jah23
New Member
3 1 0

Hello! 

I am using JQuery to render quantity selections on my product page. This is because we have a special case where after the number 36, the quantities multiply by 36 (36, 72, 108...) . The issue I am having is that any number after 35, does not get passed to the cart as an actual quantity. How can I change the JQuery to actually send the number to the cart as a quantity? 

For reference, here is my liquid code for quantities < 36: 
(these values get passed to the cart as actual quantities with no problem)

<select id="quantity" name="quantity">
	{%- for i in (1..35) -%}
  	<option selected="true" style="display:none;">Select Quantity:</option>
	 <option value="{{ i }}">{{ i }}</option>
	{% endfor %} 
</select>

 

 

And, here is my JQuery I am using to render our quantity tiers, above the number 36: 
(these values display in the front-end, but do not get passed to the cart as actual quantities)

  $(function() {
  var i = 0;  
  while (i * 36 <= 828){    
    i = i + 1;
    var num = i * 36;  
    var options = $('<option value="${num}">' + num + '</option>');
    $("#quantity").append(options.clone());
    console.log(num);    
   }    
    console.log( "Function 36" );   
});

 

Is there anyway I can change the JQuery to have the 'num' value be passed to the cart as a quantity value? Maybe using the Cart API? I am open to all suggestions.

What happens is, if the user selects any quantity above 35, the quantity value is not reflected accurately on the cart page. Any help would be greatly appreciated. 


0 Likes
jah23
New Member
3 1 0

This is an accepted solution.

Got the issue resolved by adding adding 

.val(num)

 

Here is the updated code: 

$(function() {
  var i = 0;  

  while (i * 36 <= 828){    
    i = i + 1;
    var num = i * 36;  
    var options = $("<option value='${num}'>"+num+"</option>");
    $("#quantity").append(options.clone().val(num));   
    console.log(num);    
   }    
    console.log( "Function 36" );   
});
0 Likes