Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  128] [ 5]  / answers: 1 / hits: 33044  / 10 Years ago, sun, september 28, 2014, 12:00:00

I am using Struts2 to upload multiple files:



<s:file name=files multiple=multiple />


When I select multiple files it displays the number of files, eg. 3 files.



The project requirements are that the user should be able to see what files he selected before uploading.



Is it possible to display the selected files names in a list or maybe in the control itself ?


More From » html

 Answers
1

You can use the HTML5 files property of the <input type=file /> element like follows:







updateList = function() {
var input = document.getElementById('file');
var output = document.getElementById('fileList');
var children = ;
for (var i = 0; i < input.files.length; ++i) {
children += '<li>' + input.files.item(i).name + '</li>';
}
output.innerHTML = '<ul>'+children+'</ul>';
}

<input type=file multiple
name=file
id=file
onchange=javascript:updateList() />

<p>Selected files:</p>

<div id=fileList></div>




[#69309] Thursday, September 25, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reina

Total Points: 241
Total Questions: 82
Total Answers: 94

Location: New Caledonia
Member since Thu, Mar 23, 2023
1 Year ago
;