Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  145] [ 6]  / answers: 1 / hits: 28050  / 12 Years ago, mon, january 21, 2013, 12:00:00

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?


More From » jquery

 Answers
12

The fiddle you provided contains the answer.



var numFiles = $(input:file, this)[0].files.length;


http://jsfiddle.net/xvLAc/1/


[#80721] Sunday, January 20, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austonjuancarlosb

Total Points: 238
Total Questions: 89
Total Answers: 99

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;