Sometimes, we want to get value of input type file with JavaScript.
In this article, we’ll look at how to get value of input type file with JavaScript.
How to get value of input type file with JavaScript?
To get value of input type file with JavaScript, we use the files
property.
For instance, we write
const file = document.forms["formName"]["inputName"].files[0];
to get the file input with name attribute inputName
in the form with name attribute formName
with document.forms["formName"]["inputName"]
.
Then we get the selected files from the files
property.
And we get the first file selected with index 0.
Conclusion
To get value of input type file with JavaScript, we use the files
property.