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

128
Views
¿Podemos declarar una función dentro de eventlistner y llamarla desde afuera?

Aquí he declarado una función "driverDetailsValidation" dentro del detector de eventos. Quiero llamarlo desde fuera del detector de eventos. Este es el código que he usado pero no funciona.

 driverType.onchange = function(e) { var isWithoutDriver = (driverType.value == "without driver"); if(!isWithoutDriver){ driverDetailsValidation(); } } const driver_fields = document.getElementsByClassName("driver_fields"); form.addEventListener("submit", (event) => { validity = true; function driverDetailsValidation() { for (let i = 0; i < driver_fields.length; i++) { if (driver_fields[i].value == "") { driver_fields[i].style.border = "2px solid rgb(228, 29, 22)"; driver_fields[i].style.backgroundColor = "rgba(238, 156, 156, 0.788)"; //fields[i].placeholder = "This Field is Compulsory!"; validity = false; } } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podría declarar una variable fuera del detector de eventos y asignarle la función dentro del detector. Luego, puede llamar a la función desde la variable de esta manera:

 var fct; document.querySelector("div").addEventListener("click", function() { fct = function() { alert("Working"); } }); setInterval(function() { if (fct != null) { fct(); fct = null; } }, 0);
 <div> Click me </div>

Pero en realidad no tiene sentido, creo.

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!