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

106
Views
Creating HTML Input based calculator

So i'm trying to create an html input based calculator, it just keeps returning *This is a snippet added on later, but How would i do this in jQuery *

[object HTMLInputElement][object HTMLInputElement]

so heres my code

<html>
<head>

</head>

<body>
        <input id="nume" type="number">
        <input id="num" type="number">
        <input type="button" onclick="MyFunction()" value="Click to calculate">
        <p id="f">Value Is: 0</p>
</body>
<script>
    const something = document.getElementById("nume")
    const somethingElse = document.getElementById("num")
    function MyFunction(){
    var values = something + somethingElse;
    document.getElementById("f").innerHTML = "Value Is: " + values
    }
    
</script>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

you need to get value first. document.getElementById("nume").value You can do it this way

    function MyFunction(){
    var values = Number(document.getElementById("nume").value) + Number(document.getElementById("num").value);
    document.getElementById("f").innerHTML = "Value Is: " + values
    }
    
<html>
<head>

</head>

<body>
        <input id="nume" type="number">
        <input id="num" type="number">
        <input type="button" onclick="MyFunction()" value="Click to calculate">
        <p id="f">Value Is: 0</p>
</body>

about 4 years ago · Juan Pablo Isaza Report

0

You have to use Number(document.getElementById("nume").value) to get the actual number. by just using document.getElementById("nume") you are getting the HTML DOM element and not the element's value.

about 4 years ago · Juan Pablo Isaza Report

0

  1. Firstly your code has the two variables which should be inside the function
  2. Secondly to access the value attribute of <input>
  3. thirdly I got number as string so i converted form string to number using Number();
<html>
<head>
</head>
<body>
    <input id="nume" type="number"><br/>
    <input id="num" type="number"><br/>
    <input type="button" onclick="MyFunction()" value="Click to calculate"><br/>
    <p id="f">Value Is: 0</p>
</body>
<script>
    function MyFunction(){
      var something=document.getElementById("nume").value;
      var somethingElse = document.getElementById("num").value;
      document.getElementById("f").innerHTML=Number(something)+Number(somethingElse);
    }
</script>
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!