Categories
JavaScript Answers

How to get file name when user select a file from the file input with JavaScript?

Spread the love

Sometimes, we want to get file name when user select a file from the file input with JavaScript.

In this article, we’ll look at how to get file name when user select a file from the file input with JavaScript.

How to get file name when user select a file from the file input with JavaScript?

To get file name when user select a file from the file input with JavaScript.

For instance, we write

document.getElementById("fileInput").onchange = (e) => {
  console.log(e.target.value);
};

to select the file input with getElementById.

Then we set its onchange property to a function that get the selected file’s name with e.target.value.

Conclusion

To get file name when user select a file from the file input with JavaScript.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.