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

239
Vistas
Check whether all input fields are filled out, then call function js

I have a sports betting calculator, this has several input fields, as soon as all fields are filled out, the calculated table should be displayed below.

When the table is displayed, it should be possible to change the input fields; the table should then also change in real time.

HTML: <input type="number" class ="form-control input-lg" id="quoteBack">

JS:document.getElementById("quoteBack").addEventListener("input", function() {});

I am currently using the addEventListener "input" variant, this can only be used on one field.

But I want to check that all fields are filled out, then the table should appear

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

0

Hmm, first of all, I think you should give the input field a unique className, then we just gonna check the fields that have that className.

For example:

<input type="number" class ="form-control input-lg validated-field" id="quoteBack">

I gave it a className called validated-field.

Then let's check those fields using JavaScript:

// Get fields by className
var fields = document.getElementsByClassName("validated-field")

// Array.from will convert the HTMLCollection to Native Array.
if (Array.from(fields).length > 0) {
  // Loop
  Array.from(fields).forEach(field => {
    // Add Event for each field.
    field.addEventListener("input", function(e) {
      console.log(e.target.value)
      if (!e.target.value) {
        e.target.classList.add("not-valid")
      } else {
        e.target.classList.remove("not-valid")
      }
    })
  })
}

I just loop through the fields and add an event listener for each field.

Live Example: https://codepen.io/nawafscript/pen/OJjEXrW

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