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

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

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 Denunciar

0

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

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