lundi 29 avril 2019

Making PHP variable specific on jQuery each function

So I am trying to validate items in my cart, by hiding the add button whenever a user's item quantity is more than the stock, the code works fine whenever there is one item in it, however when there is multiple items, my stock variable only gets the last item's stock in the cart, not all of them

This is my code below

$('.quantity-val').each(function() {
                var initialQuantity = parseInt($(this).text());
                if (initialQuantity === 0) {
                    $(this).siblings('.fa-minus-circle').hide();
                }

                var quantity = '<?php echo $details['stock'] ?>';

                console.log(initialQuantity);
                console.log(quantity);

                if (initialQuantity == quantity) {
                    $(this).siblings('.fa-plus-circle').hide();
                }

            });

I believe I would need to make the quantity variable specific but not sure how to..

Any help would be greatly appreciated!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2XToBZz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire