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

95
Views
Making live forms on html+js

I'm making site to make table game calculations easier. So, if simplify, I have a form like this:

<input id="x"/>
<input id="y"/>

And I want to collect data of this form in live time and process them like this immediately:

<span id="x-plus-y"/> in html and document.getElementById('x-plus-y').innerHTML = x*y in js

It's very simplified but I think you got the thought.

My question is how to process x+y immediately as the user enters the values into the input fields.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is the simple approach you can go through. I have attached a keyup event listener on every input and then invoking the updateResult function which calculates the product and displays it within the result div.

HTML

 Number 1 : <input type="number">
 <br><br>
 Number 2 : <input type="number">
 <br><br>
 <div id="result">
 </div>

JS

const inputs = Array.from(document.querySelectorAll("input"));
const resultDiv = document.querySelector("div");
const numbers = [];
for(const input of inputs) {
  input.addEventListener('keyup', updateResult);
}

function updateResult() {
   let product = 1;
   for(const input of inputs) {
       product*= parseInt(input.value,10);
    }
    if(!isNaN(product)) {
        resultDiv.innerHTML = "Product: " + product;
    }
}
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!