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

158
Visualizações
value in input is undefined

I'm making AP calculator but the answer value is undefined in the input field of answer having id "An" please help; here's my code:

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>JavaScript Example</title>
</head>

<body>
    <!-- first term -->
    <input type="text" value="1" name="" id="a1" onkeyup="ap()">
    <!-- number of term -->
    <input type="text" value="2" name="" id="n" onkeyup="ap()">
    <!-- difference -->
    <input type="text" name="" value="3" id="d" onkeyup="ap()">
    <input type="text" name="" id="An">

    <script>
        ap()

        function ap() {
            let a1 = document.getElementById("a1").value;

            let n = document.getElementById("n").value;
            let d = document.getElementById("d").value;
            var An = Number(a1) + ((Number(n) - 1) * Number(d));
            console.log(An)
            document.getElementById("An").value = An.value
        }
    </script>
</body>

</html>
please help in solving the issue.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Change the An.value to jut An, since An is just a variable

document.getElementById("An").value = An;
about 4 years ago · Juan Pablo Isaza Relatório

0

You must assign the variable 'An' direct in the value.

document.getElementById("An").value = An
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