Problems to reference elements of the sun. Also doubt with each

0

                                                                                                                                                                                                                                                                                                                                                                                                                                         

                                        <td class="product-name">
                                            <a href="single-product.html">Juan ramon ibañez</a> 
                                        </td>

                                        <td class="product-price">
                                            <span class="amount">600.40 €</span> 
                                        </td>

                                        <td class="product-quantity">
                                            <div class="quantity buttons_added">

                                                <input type="number" size="4" class="input-text qty text cantidax" title="Qty" value="2" min="0" step="1" > 

                                                <a href="" class="btn btn-warning actualizaCantidad" ><i class="fa fa-refresh"></i></a>
                                            </div>
                                        </td>

                                        <td class="product-subtotal">
                                            <span class="amount"></span> 
                                        </td>
                                    </tr>


                                    <tr class="cart_item">
                                        <td class="product-remove">
                                            <form method="POST" action="" accept-charset="UTF-8"><input name="_method" type="hidden" value="DELETE"><input name="_token" type="hidden" value="qtviOQDNvRIOVAO0RFUKF4UKfWs9LGrKHpScuzKR">
                                            <input type="submit" value="x" title="Eliminar este elemento" class="remove" > 
                                            </form>
                                        </td>
                                            <form method="POST" action="c" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="qtviOQDNvRIOVAO0RFUKF4UKfWs9LGrKHpScuzKR">
                                        <td class="product-thumbnail">
                                            <a href="single-product.html"><img width="145" height="145" alt="poster_1_up" class="shop_thumbnail" src="/ima/1.jpg"></a>
                                        </td>

                                        <td class="product-name">
                                            <a href="single-product.html">Manuel Bernal Garcia</a> 
                                        </td>

                                        <td class="product-price">
                                            <span class="amount">200.20 €</span> 
                                        </td>

                                        <td class="product-quantity">
                                            <div class="quantity buttons_added">

                                                <input type="number" size="4" class="input-text qty text cantidax" title="Qty" value="1" min="0" step="1" > 

                                                <a href="" class="btn btn-warning actualizaCantidad"  ><i class="fa fa-refresh"></i></a>
                                            </div>
                                        </td>

                                        <td class="product-subtotal">
                                            <span class="amount"></span> 
                                        </td>
                                    </tr>

   <tr>
                                        <td class="actions" colspan="6">

                                            <input type="submit" value="Actualiza Importes" name="update_cart" class="button actualiza_importe_compra" >
                                            <input type="submit" value="Pagar" name="proceed" class="checkout-button button alt wc-forward">
                                        </td>
                                    </tr>

The idea is this, this is the final source code of a project I'm doing. I have put only two rows since the code is dynamic, and it is a repetition of the tr with the cart_item class.

What I want is that when you click on the button with the class. update_import_buy add up all the totals of each row, but when using an input number to modify the quantity is failing me, that is why to find the total of totals , you would have to find all the prices multiplied by the quantity of each row and go adding them (accumulating them). The problem I have when referencing each price and each quantity using the each, which by the way I have not used much

    $('.actualiza_importe_compra').click(function()

     {  

            var inputCantidad = parseInt($(this).parents('tr').find('input.cantidax'));
            var precio = parseFloat($(this).parents('tr').find('.product-price.amount'));
            $.each(function(index,value)
            {
                var total = inputCantidad.val() * precio.text();

                    console.log(total);
            });

            return false;

 });

        });

This is what I have but it does not work for me, I have problems to reference when pressing the button the quantity and the dynamic price.

    
asked by KurodoAkabane 16.08.2016 в 19:56
source

1 answer

1

I think that with this example you could have an idea of how to implement it

[ASP.NET] - GridView add columns with jquery

You'll see that to go through the table and add a columan you would use

var total = 0;
$('#TablaId tr:not(:last)').each(function() {

    var coltotal = parseFloat($("td:eq(3) span", this).html());

    if (!isNaN(coltotal)) {
        total += coltotal;
    }

});

In this case, as I had a footer in the table, use :not(:last) but if not, you can remove it, the idea is to iterate every tr with td:eq(3) you select the third column, in this case it contained a span , but you can change this by : text

    
answered by 16.08.2016 / 20:55
source