Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda