How can I count the number of files that are in the file upload input using jQuery?
I have tried this but it always returns 1:
$("body").on("change", ".create-album .custom-file-input .createAlbumFileUpload", function(){
var numFiles = $("input:file", this).length;
alert(numFiles);
});
My HTML:
<form enctype="multipart/form-data" class="createAlbumFileUpload">
<input type="file" name="uploadFile[]" multiple="multiple"/>
</form>
I found this jsFiddle on another question asking the same thing, however I can't see why mine isn't working?
The fiddle you provided contains the answer.
var numFiles = $("input:file", this)[0].files.length;
http://jsfiddle.net/xvLAc/1/
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