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

153
Views
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 answers
Answer question

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 Report

0

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

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