Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  105] [ 2]  / answers: 1 / hits: 143489  / 13 Years ago, thu, august 11, 2011, 12:00:00

Possible Duplicate:

Retrieving file names out of a multi-file upload control with javascript






From HTML5 input type=file allows users to choose multiple files by adding the multiple=multiple :



<input type=file multiple=multiple />


My question is: how can I get the value of that input? When using the .value it only returns the filename of the first file selected, but when choosing more than one I am not able to view the other ones.



What I have:



<input type=file multiple=multiple onchange=alert(this.value)
onmouseout=alert(this.value) />


which as I told you, is only showing the name of one of the selected files.



NOTE: I don't want to edit the value (I know that is not possible) only the name of the files



Thanks!


More From » html

 Answers
48

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);
}

[#90682] Tuesday, August 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;