• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

81
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.

almost 3 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;
    }
}
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error