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

154
Vistas
how to get table input sum value depend on select box?

The HTML part of the code below works when I use it without a table but does not work when the inputs of the form are placed inside the row of the table. Basically the total will be down according to the celestial box. Can anyone help please?

<script> 
$(document).on("change", ".track,[name='type[]']", function() {
  const sum = {
    male: 0,
    female: 0
  };
  $(".track").each(function() {
    const type = $(this).prev().val();
    sum[type] += +$(this).val();
  });
  $("#male-total").val(sum.male);
  $("#female-total").val(sum.female);
});
</script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>

  <table widht="100" border="1" >
           <tr>
              <th><select name='type[]'><option value='male'>Male</option><option value='female'>Female</option></select></th>
              <th><input type="text" name="amount[]" class="track" value="" /> </th>
           </tr>               
           
           <tr>
              <th><select name='type[]'><option value='male'>Male</option><option value='female'>Female</option></select></th>
              <th><input type="text" name="amount[]" class="track" value="" /> </th>
           </tr>
     </table>     
      
          
          
 <hr> 
    <label> Male Total: </label>
    <input type="text" id="male-total"  value="" />
    
        <label> Female Total: </label>
    <input type="text" id="female-total"   value="" />
    

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