Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda