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 ?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.