Get input type="file" value when it has multiple files selected [duplicate]
Solution 1:
The files selected are stored in an array: [input].files
For example, you can access the items
// assuming there is a file input with the ID `my-input`...
var files = document.getElementById("my-input").files;
for (var i = 0; i < files.length; i++)
{
alert(files[i].name);
}
For jQuery-comfortable people, it's similarly easy
// assuming there is a file input with the ID `my-input`...
var files = $("#my-input")[0].files;
for (var i = 0; i < files.length; i++)
{
alert(files[i].name);
}
Solution 2:
You use input.files
property. It's a collection of File objects and each file has a name
property:
onmouseout="for (var i = 0; i < this.files.length; i++) alert(this.files[i].name);"