Reputation: 171
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 ?
Upvotes: 0
Views: 60
Reputation: 3845
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.
Upvotes: 1