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

251
Visualizações
The specified value "undefined" cannot be parsed, or is out of range

SO I am trying to make a POS web based app in the billing part I am trying to add the total column only that are added by the JavaScript but it doesn't adds up

HTML: -

            <table id="tbl">
              <thead>
                <th>Product Name</th>

                <th>Description</th>

                <th>Price</th>

                <th>Quantity</th>

                <th>Total</th>
              </thead>
            </table>

I have created a button that dose a couple of things other then this, it should show the summed amount in the input field but this JS doesn't shows the summed amount: -

let subTotal = document.getElementById("tbl").getElementsByTagName("td");

  let sum;

  for (let i = 0; i < subTotal.length; i++) {
    if (subTotal[i].id == "lstTtl") {
      sum += isNaN(subTotal[i].innerHTML) ? 0 : parseInt(subTotal[i].innerHTML);
    }
  }

  document.getElementById("sTotal").value = sum;

Trying to get a calculated amount from a table that is added dynamically.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

isNaN will always return true for anything that isn't a number, which subTotal[i].innerHTML never is, therefore sum will always be +0.

if (subTotal[i].id == "lstTtl") {
  const num = parseInt(subTotal[i].innerHTML);
  if(!isNaN(num) {
    sum += num;
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
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