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.