Access file names from multiple files

I want to read the file names of my multiboot form, however Javascript just adds only the first element.

<input name="upload[]" id="upload" type="file" multiple="multiple"> 
 $("#upload").change(function() { $("#upload").each(function() { $("#upload_prev").append(this.value); }); }); 
+6
source share
1 answer

Several file upload fields are not yet very well supported by jQuery. Your best option is to revert to your own javascript to access the files collection. Try the following:

 $("#upload").change(function() { var files = $(this)[0].files; for (var i = 0; i < files.length; i++) { $("#upload_prev").append(files[i].name); } }); 

Script example

In addition, here is a fiddle with several problems with your example fixed, for example, clearing the previous list of files when reselecting and adding the file name to a new line: http://jsfiddle.net/Vs5Hk/3/

+11
source

Source: https://habr.com/ru/post/914207/


All Articles