0

i want to execute some code only if user has clicked on "add file" (when we use an input type file in html) and selected a file. Is there a way to do this ?

vincent05996
  • 131
  • 1
  • 11

1 Answers1

1

Yes, you can work with the input event like this:

const input = document.querySelector('input');

input.addEventListener('input', updateValue);

function updateValue(e) {
  log.textContent = e.target.value;
}

You can of course modify this to suit your requirement. This example is from the Mozilla documentation here

Take a look at this answer which you may also find useful. It works with the change event.

Nick
  • 3,454
  • 6
  • 33
  • 56