Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda