KACKbIP
4 months ago

when I increment or decrement all the values changed. How to change only specific value

Posted 4 months ago by KACKbIP
        jQuery(document).ready(function(){
            // This button will increment the value
            $(".qtyplus").click(function(e){
                // Stop acting like a button
                e.preventDefault();
                // Get the field name
                fieldName = $(this).attr('field');
                // Get its current value
                var currentVal = parseInt($('input[name='+fieldName+']').val());
                // If is not undefined
                if (!isNaN(currentVal)) {
                    // Increment
                    $('input[name='+fieldName+']').val(currentVal + 1);
                } else {
                    // Otherwise put a 0 there
                    $('input[name='+fieldName+']').val(1);
                }
            });
            // This button will decrement the value till 0
            $(".qtyminus").click(function(e) {
                // Stop acting like a button
                e.preventDefault();
                // Get the field name
                fieldName = $(this).attr('field');
                // Get its current value
                var currentVal = parseInt($('input[name='+fieldName+']').val());
                // If it isn't undefined or its greater than 0
                if (!isNaN(currentVal) && currentVal > 1) {
                    // Decrement one
                    $('input[name='+fieldName+']').val(currentVal - 1);
                } else {
                    // Otherwise put a 0 there
                    $('input[name='+fieldName+']').val(1);
                }
            });
        });
</script>

it is my Javascript

 @foreach($cart as $ca)
                            <div class="callout cart-product-item inline-block-container" data-product-id="{{ $ca->id }}" id="{{ $ca->id }}">
                                <div class="inline-block-item vertical-middle cart-product-item-preview">
                                    <img src="{{ asset("images/{$ca->attributes->image}") }}" alt="">
                                </div>
                                <div class="inline-block-item vertical-middle cart-product-item-info">
                                    <div class="inline-block-container">
                                        <div class="inline-block-item vertical-middle cart-product-item-desc">
                                            <a href="/catalog/motokultivatory/motoblok_power_tiller_fgt_7_100g.html" class="cart-product-item-name">
                                                {{ $ca->name }}                                            </a>                                                                                        <a href="#" class="button transparent add2liked" data-ajax="/nl_ajax/favorite.php" data-product-id="2719">
                                                <svg class="icon">
                                                    <use xlink:href="#svg-icon-liked"></use>
                                                </svg>
                                                <span>В избранное</span>
                                            </a>
                                        </div>
                                        <div class="inline-block-item vertical-middle cart-product-item-price medium-up-2 large-up-3">
                                            <div class="column">
                                                <div class="product-count">
                                                    <div class="product-info-caption">Количество</div>
                                                    <div class="input-group">
                                                        <div class="input-group-button">
                                                            <button class="button decrement qtyminus" type="submit" name="decr" field='quantity'>-</button>
                                                        </div>

                                                        <input class="input-group-field" type="number" id="bx_3966226736_2425_quantity" name="quantity" value="{{ $ca ? $ca->quantity : 1  }}" min="1">

                                                        <div class="input-group-button">

                                                                <button  class="button increment qtyplus" type="submit" name="inc" field='quantity' >+</button>
                                                        </div>
                                                    </div>
                                                    <input type="hidden" id="QUANTITY_1323" name="QUANTITY_1323" value="1" />
                                                </div>
                                            </div>
                                            <div class="column float-right">
                                                <div class="product-price">
                                                    <div class="product-info-caption">Итого:</div>
                                                    <div class="main" id="total_price_1323">{{ number_format($ca->price * $ca->quantity) }} ₸.</div>
                                                </div>
                                            </div>
                                            <div class="column show-for-large">
                                                <div class="product-price">
                                                    <div class="product-info-caption">Цена за  штуку</div>
                                                    <div class="main" id="current_price_1323">{{ number_format($ca->price) }} ₸.</div>
                                                    <div class="old" id="old_price_1323" data-old-price="0"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <button class="close-button" type="button" onclick="cartAjaxAction('/nl_ajax/cart.php', 'delete', '1323')">
                                    <span aria-hidden="true">+</span>
                                </button>
                            </div>
                            @endforeach```
this is my view

Please sign in or create an account to participate in this conversation.