0

I have a multiple file input like this:

<input multiple="multiple" type="file" name="file">

When I click it, I get the option to select some files. When I select some files click on "open", I need to display the number of files I selected (let's say in an alert box). I suppose there should be a javascript event to handle this situation, but I can't find it. How could I accomplish this?

I have tried searching around stackoverflow but haven't found a solution, although this question doesn't seem overly specific.

icarus
  • 166
  • 1
  • 6
  • 14
  • 1
    possible duplicate of [HTML5: How to count the length of the files from the multiple-input field](http://stackoverflow.com/questions/7139244/html5-how-to-count-the-length-of-the-files-from-the-multiple-input-field) – MrUpsidown Aug 12 '14 at 12:51
  • 1
    [**How to count selected file**](http://stackoverflow.com/questions/9232633/how-to-count-selected-files) [Demo](http://jsfiddle.net/nze2B/104/) – Shubh Aug 12 '14 at 12:54
  • 1
    @MrUpsidown: thank you, I haven't stumbled across that question and I searched a great deal for this issue.. I'll pay more attention next time. – icarus Aug 12 '14 at 13:00

2 Answers2

3

try this:-

$("input[type='file']").on("change", function(){  
  var numFiles = $(this).get(0).files.length
   alert(numFiles);
});

Demo

Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
2
$("input[type='file']").eq(0).files.length;
Curtis
  • 101,612
  • 66
  • 270
  • 352