Sum of td with class

0

Hello, how can I add the values of the column with the class called add <td class="sumar">VALOR ENTERO</td> taking into account that it is a cycle foreach and several values will be printed with the same class.

<table cellspacing="0" class="table table-hover table-bordered">
            <thead>
                <tr>
                    <th>CANT.</th>
                    <th>ARTICULO</th>
                    <th>V.UNITARIO</th>
                    <th>V.TOTAL</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($prod_alquilado as $producto): ?>
                    <tr>
                        <td><?php echo $producto['cantidad'] ?></td>
                        <td><?php echo $producto['articulo'] ?></td>
                        <td><?php echo "$".$producto['valor_unitario'] ?></td>
                        <td class="sumar"><?php echo ($producto['valor_unitario']*$producto['cantidad']) ?></td>
                    </tr>
                <?php endforeach ?>
                <tr>
                    <th style="text-align: right;" colspan="3">TOTAL:</th>
                    <td>$</td>
                </tr>
            </tbody>
        </table>

I remain attentive.

    
asked by ByGroxD 01.09.2017 в 08:36
source

1 answer

0

Make a javascript file that collects the values contained in the column sumar

var list = document.getElementsByClassName("sumar");

For this you need to add an array: class="sumar[]"

And it does not simply go through the array and you add the values it contains.

for (var i=0;i<list.length;i++) {
    //Sumar
}
    
answered by 01.09.2017 в 08:50