Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Resetting all the other inputs If the values reach higher than a specified value javascript

So I have 3 input boxes in HTML

<input type="number" id="geoOnePercentage" placeholder="Geo 1 Percentage" />
<input type="number" id="geoTwoPercentage" placeholder="Geo 2 Percentage" />
<input type="number" id="geoThreePercentage" placeholder="Geo 3 Percentage" />

What I want to do is that as the user types into these input boxes keep checking If their total exceeds the value of 100, as soon as the user types a value that makes the total exceed 100 reset the form.

For example, the user typed 50 in the first input box, that's okay. Then the user typed 40 in the next input box, that's okay as well, BUT THEN If the user types a value such as 15 which makes the total of all the input boxes' values combined exceed, then reset the values of all 3 input boxes.

However, I have no idea how to do this. I have learned a bit about onkeydown event thing in JavaScript but It's not working as I expected.

If someone were to shed some light on how this could be done, I would really appreciate it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

let inputs = [...document.querySelectorAll('input[type="number"]')];

inputs.forEach(inp => inp.addEventListener('input', function() {
  const total = inputs.reduce((acc, inp) => acc + Number(inp.value), 0);
  if (total > 100) {
    inputs.forEach(inp => inp.value = '');
  }
}))
<input type="number" id="geoOnePercentage" placeholder="Geo 1 Percentage" />
<input type="number" id="geoTwoPercentage" placeholder="Geo 2 Percentage" />
<input type="number" id="geoThreePercentage" placeholder="Geo 3 Percentage" />

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda