Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!