KACKbIP
4 months ago

have a problem with the array

Posted 4 months ago by KACKbIP

    <script>
        $(document).on('click', '.number-spinner button', function () {
            var btn = $(this);
            var oldValue = btn.closest('.number-spinner').find('input').val().trim();
            var proid = btn.closest('.spin2').find('input').val().trim();
            // var price = document.getElementById('proprice-' + proid).value;

            var oldValue2 = document.getElementById('p-' + proid).innerText;

                newVal = 0;

                newVal2 = 0;
            var all = [oldValue2];

            all = oldValue2;

            alert(all);

            if (btn.attr('data-dir') == 'up') {
                newVal = parseInt(oldValue) + 1;
                newVal2 = parseInt(oldValue2) * newVal;

            } else {
                if (oldValue > 1) {
                    newVal = parseInt(oldValue) - 1;
                    newVal2 =parseInt(oldValue2)  * newVal ;

                } else {
                    newVal = 1;
                    newVal2 = parseInt(oldValue2) * newVal;
                }
            }
            btn.closest('.number-spinner').find('input').val(newVal);
            document.getElementById('p-' + proid).innerText = newVal2;
        });

    </script>

I tried to save to use the variable all as an array. But a new variable is overwrite it. I need to get a value like this:

all = [oldValue2[first_value], oldValue2[second_value] ...]

but it saves all = [oldValue2[last_value], oldValue2[last_value] ...]

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