I want to read out the filenames of my multi upload form, however Javascript is just adding the first item only.
<input name="upload[]" id="upload" type="file" multiple="multiple">
$("#upload").change(function() {
$("#upload").each(function() {
$("#upload_prev").append(this.value);
});
});
Tip: For <input type="file"> : To select multiple files, hold down the CTRL or SHIFT key while selecting.
The FileUpload. AllowMultiple property in . NET 4.5 and higher will allow you the control to select multiple files.
Uploading Multiple Files const uploadFile = (files) => { console. log("Uploading file..."); const API_ENDPOINT = "https://file.io"; const request = new XMLHttpRequest(); const formData = new FormData(); request. open("POST", API_ENDPOINT, true); request. onreadystatechange = () => { if (request.
Multiple file upload fields are not yet very well supported by jQuery. Your best option is to revert to native javascript to get access to the files
collection. Try this:
$("#upload").change(function() {
var files = $(this)[0].files;
for (var i = 0; i < files.length; i++) {
$("#upload_prev").append(files[i].name);
}
});
Example fiddle
Also, here's a fiddle with a couple of the issues with your example fixed, such as clearing the previous list of files when re-selecting and appending the filename on a new line: http://jsfiddle.net/Vs5Hk/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With