Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!