Skip to content

Instantly share code, notes, and snippets.

@alegut
Last active July 5, 2018 11:52
Show Gist options
  • Select an option

  • Save alegut/848eeb145f544e3bfdea12542e5ac77a to your computer and use it in GitHub Desktop.

Select an option

Save alegut/848eeb145f544e3bfdea12542e5ac77a to your computer and use it in GitHub Desktop.
Increase-decrease input value
jQuery(document).on('click', '.jq_decrease, .jq_increase', function(){
var current_action = jQuery(this).data('quantity');
var pevious_val = jQuery(this).parent('.quantity_box').find('.jq_qty input').val();
if(current_action == 'increase'){
var qty_item = parseInt(pevious_val) + parseInt(1);
}else if(current_action == 'decrease'){
if(parseInt(pevious_val) - parseInt(1) <= parseInt(0)){
var qty_item = 0;
}else{
var qty_item = parseInt(pevious_val) - parseInt(1);
}
}
jQuery(this).parent('.quantity_box').find('.jq_qty input').val(qty_item).trigger('change');
});
<div class="product__quantity quantity_box">
<div class="decrease jq_decrease product__quantity-btn product__quantity-btn--remove" data-quantity="decrease">
<img src="assets/images/i-remove.svg" alt="Remove" class="product__quantity-btn-icon">
</div>
<div class="qty jq_qty product__quantity-total">
<!-- <p class="product__quantity-total-label">@if ($product->id){{ $product->qty }}@else {{0}} @endif</p> -->
<input class="product__quantity-total-label" type="number" min="0" max="999" value="@if ($product->id){{ $product->qty }}@else {{0}} @endif" disabled name="quantity">
</div>
<div class="increase jq_increase product__quantity-btn product__quantity-btn--add" data-quantity="increase">
<img src="assets/images/i-add.svg" alt="Add" class="product__quantity-btn-icon">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment