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

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

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