Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  74] [ 7]  / answers: 1 / hits: 22039  / 11 Years ago, mon, july 1, 2013, 12:00:00

In my HTML i select multiple files.



<input type=file id=img multiple>


I want to store each element in an array so that i can print the file source.



I have done this in my javascript but it does not work.



function loadfiles()
{
var x=document.getElementById(img);
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].src);
}
}

More From » dom

 Answers
20

The property files gets you an array of all the files selected by the file input. So the loadfiles function should be modified to following:



function loadfiles()
{
var imageFiles = document.getElementById(img),
filesLength = imageFiles.files.length;
for (var i = 0; i < filesLength; i++) {
document.write(imageFiles.files[i].name);
}
}

[#77287] Saturday, June 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
frederickmohamedw questions
Wed, Sep 23, 20, 00:00, 4 Years ago
Sat, Jul 18, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Sat, Jan 11, 20, 00:00, 4 Years ago
Fri, Dec 27, 19, 00:00, 4 Years ago
;