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

250
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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