Update value within a Foreach


please help me, I need to update the result of my total every time I change the amount

                                <script type="text/javascript">
                                    function operacion(field) {
                                        //Obtengo el formulario
                                        var form = field.parentNode; 
                                        //Obtengo el valor del campo 1
                                        var numero1 = form.cantidad.value; 
                                        //Obtengo el valor del campo 2          
                                        var numero2 = form.precio.value;
                                        //Hago el calculo y se lo asigno al campo de texto correspondiente          
                                        form.total.value = ( numero1 * numero2 );                                                                              
    foreach ($sql_Producto as $itemListarProductoCarrito):
    $preci = $itemListarProductoCarrito['costo_promedio_producto'];
     <table  class="table table-bordered">                                                                   
      <a href="eliminardelcarro.php?id=<?php echo $c["product_id"]; ?>" class="fa fa-fw fa-minus-circle" data-toggle="tooltip" title="Eliminar"></a>
    <!--aqui le aumento para la cantidad para poder modificar si el ususario lo desea-->
    <select name="cantidad" style="width:100px;" class="form-control" onchange="operacion(this)" >
        <option value="<?php echo $c["q"]; ?>"><?php echo $c["q"]; ?></option>
        <option value=""></option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    <td><label>Precio Unitario</label></td>
    <td><input align="right" style="width:100px;" class="form-control" type="text" name="precio" value="<?php echo $preci;/*recibo mi precio*/ ?>"  onchange="operacion(this)"  readonly></td>
        <td><input align="right" style="width:100px;" class="form-control" type="text" name="total" value="<?php echo '$' . $total = $c["q"] * $preci; /*aqui multiplico la cantidad enviada * por el precio*/?>"readonly></td>
        <?php $totalProducto += $total;/*sumo todos los valores totales*/ ?>


until everything works fine since I add all the values within my foreach Now I need to add the values but now these with a SELECT to change the amount since the amount $ c ["q"] sends me from another form but I can not with the new amount since I would be containing it with the name="total" I think it would be something to do something but I can not think of it as

asked by Jhon Di 28.09.2018 в 18:44

0 answers