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

64
Views
javascript sum input of type text

i was trying to sum 2 input of type text(I've already a function that allows only floats so the format isn't a problem) and i don't know why it keeps returning a NaN and how to fix it. Can anyone help me? html:

<form>
    <input type="text" id="num1"/>
    <p2>+</p2>
    <input type="text" id="num2"/>
    <input type="submit" value="Calc" onclick="calc()"/>
    <p2 id="res"></p2>
</form>

javascript:

function calc() {
    var res;
    //...
    document.getElementById("res").innerHTML=res;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can compute the sum as follows:

function calc() {
    var a = parseFloat(document.getElementById("num1").value);
    var b = parseFloat(document.getElementById("num2").value);
    var res = a + b

    document.getElementById("res").innerHTML = res.toString();
}
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!