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

258
Views
onclick recognized, but onchange not

I probably stared to long at it - problem is smilar to this.I added an event listener to a button, but only the onclick method fires something. I want to display the name of the selected file from an upload:

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>

I fail to see why clicking on the upload button always shows in the console, but selecting a file does not trigger the changed to: ....

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

0

Your code would work if you inlcude input field with type 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!