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

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

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 Denunciar

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 Denunciar

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