• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

156
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

almost 3 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

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda