Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Dynamicly update php variable on change of multiple input fields without page reload

I'm not familiar with js and tried the example shown here (jQuery - update variable when input values changed) but it's not working for me.

What I need is the following: I have a variable, that has to show the total qty entered in input fields. I.e on every input field change I have to sum the entered qty. My code is as follow:

<?PHP
$counter = 0;
?>

<div class="total">
    TotalPcs:
    <span class="running_total">
        <?= $counter ?> <!-- this is the var showing the total qty -->
    </span>
</div>
<?php
<form method="post">
    foreach ($object->getExternalProducts($orderlang) as $result) {
        print '<tr>';
        print '<td>' . $result->label . '</td>';
        print '<td><input type="number" class="qty_field" name="productid_' .$result->rowid . '" value="" /></td>';
        print '<tr>';
    }
</form>
?>

As you can see, the name of the field is populated based on SQL query and appends the ID of each product after productid_ so I cannot use the name field. I can strip the 'productid_' but it's obvious that it is easier to use 'class' or 'id' of the field.

And the JS file:

$('body').on('keyup', '.qty_field', function () {
    var sum = 0;
    $('.qty_field').each(function() {
        sum += Number($(this).val());
    });

    $('.running_total').html(sum);
});

Any help is appreciated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda