# How to get input data dynamically without using \<button\>

**URL:** <https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [April 29, 2022, 1:47am UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606 "2022-04-29T01:47:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kedar.agate](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kedar.agate/32/242222_2.png) [@kedar.agate](https://forum.freecodecamp.org/u/kedar.agate)\
**Post date:** [April 29, 2022, 1:47am UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606/1 "2022-04-29T01:47:14Z")

</div>

I am creating compound interest calculator.  
I have selected input fields using document. querySelector, but now how to get user inputs dynamically to perform calculations

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [April 29, 2022, 1:55am UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606/2 "2022-04-29T01:55:39Z")

</div>

An input will have a `value` you can access:

```auto
document. querySelector('input').value

```

---

<div class="post-metadata">

**Author:** ![skamat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/skamat/32/240957_2.png) [@skamat](https://forum.freecodecamp.org/u/skamat)\
**Post date:** [April 29, 2022, 1:59am UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606/3 "2022-04-29T01:59:37Z")

</div>

document.getElementById(‘textboxId’).value will help you get data that the user enters in the textboxes. you can then convert it to number by using parseInt() method.

---

<div class="post-metadata">

**Author:** ![snowmonkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snowmonkey/32/241579_2.png) [@snowmonkey](https://forum.freecodecamp.org/u/snowmonkey)\
**Post date:** [April 29, 2022, 1:59pm UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606/4 "2022-04-29T13:59:46Z")

</div>

If you’d like it to happen dynamically (so the user doesn’t have to click some button), consider listening to a different event. For example, the `change` or `input` event _on that input element itself_ might be worth looking into (I’d suggest [https://developer.mozilla.org](https://developer.mozilla.org) and search for either event).

---

<div class="post-metadata">

**Author:** ![kedar.agate](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kedar.agate/32/242222_2.png) [@kedar.agate](https://forum.freecodecamp.org/u/kedar.agate)\
**Post date:** [May 3, 2022, 11:55am UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606/5 "2022-05-03T11:55:40Z")

</div>

it is not working as intended.

```auto
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="container">
      <section>
        <h3 id="main-heading">Compund Interest Calculator</h3>
        <p>
          Compound Interest was called the 8th Wonder of the World by Albert
          Einstien. It is what makes your money grow so that even small amounts
          can over time create a huge corpus. ET Money’s compound interest
          calculator is a free, online tool that you can use to find out how
          your small savings will accumulate over time to make you wealthy.
        </p>
        <div class="main">
          <form class="form">
            <p>I want to invest</p>
            <input
              type="number"
              class="investment-amount"
              placeholder="Rs. per month"
              step="1000"
              min="0"
            />
            <p>Expected rate of interest (p.a.)</p>
            <input
              type="number"
              class="expected-interest"
              placeholder="%"
              min="0"
            />
            <p>Investment Period</p>
            <label>Years</label>
            <input type="number" id="years" placeholder="years" min="0" />
            <label>Months</label>
            <input
              type="number"
              id="months"
              placeholder="months"
              max="11"
              min="0"
            /><br />
            <!-- <button type="submit" class="submit-btn">Submit</button> -->

            <p>Maturity Amount Rs.<span class="maturity-amount">0</span></p>
          </form>
        </div>
      </section>
    </main>
    <script src="script.js"></script>
  </body>
</html>

```

let investmentAmount = parseInt(

document.querySelector(".investment-amount").value

);

const expectedInterest = parseInt(

document.querySelector(".expected-interest").value

);

const years = parseInt(document.querySelector("#years").value);

const months = parseInt(document.querySelector("#months").value);

const maturityAmount = document.querySelector(".maturity-amount");

const input = document.querySelectorAll(“input”);

const form = document.querySelector(".form");

const finalAmount = function () {

let amount = Math.floor(

```
investmentAmount * (1 + expectedInterest / 100) ** years

```

);

console.log(amount);

maturityAmount.innerHTML = amount;

};

input.forEach((field) =\> {

field.addEventListener(“input”, finalAmount);

});

```auto

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [November 1, 2022, 11:56pm UTC](https://forum.freecodecamp.org/t/how-to-get-input-data-dynamically-without-using-button/506606/6 "2022-11-01T23:56:28Z")

</div>

Closed on November 1, 2022, 11:56pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
