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

257
Views
onclick reconocido, pero onchange no

Probablemente lo miré demasiado tiempo: el problema es similar a este . Agregué un detector de eventos a un botón, pero solo el método onclick dispara algo. Quiero mostrar el nombre del archivo seleccionado de una carga:

 var ulButtons = document.getElementsByClassName("file-upload"); [...ulButtons].forEach(ulButton => { ulButton.addEventListener("click", function() { ulButton.value = null; console.log("this works") }) }); [...ulButtons].forEach(ulButton => { ulButton.addEventListener("change", function() { console.log("changed to:", this.value) }) });
 <label for="{field.id_for_label}" class="file-upload btn btn-secondary">upload file</label>

No veo por qué hacer clic en el botón de carga siempre se muestra en la consola, pero seleccionar un archivo no activa el changed to: ... .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su código funcionaría si incluye un campo de entrada con el tipo de file .

 var ulButtons = document.getElementsByClassName("file-upload"); [...ulButtons].forEach(ulButton => { ulButton.addEventListener("click", function() { ulButton.value = null; console.log("this works") }) }); [...ulButtons].forEach(ulButton => { ulButton.addEventListener("change", function() { console.log("changed to:", this.value) }) });
 <label for="{field.id_for_label}" class="file-upload btn btn-secondary"> <input type="file">upload file</input></label>

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!