0

How to get a value from <input type="file" name="attach_1" multiple> using jQuery?

I did try $('input').val(), but when you use 2+ files it sends back just first one.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • you loop through them using for loop – guradio Feb 05 '16 at 10:17
  • `var file = $('#input')[0].files; for (var i = 0; i < file.length; i++) { console.log("file_" + i, file[i]); }` try this way – guradio Feb 05 '16 at 10:20
  • Possible duplicate http://stackoverflow.com/questions/3654179/retrieving-file-names-out-of-a-multi-file-upload-control-with-javascript – John R Feb 05 '16 at 10:23
  • http://stackoverflow.com/questions/7023457/get-input-type-file-value-when-it-has-multiple-files-selected – John R Feb 05 '16 at 10:24

1 Answers1

1

$('#input').change(function(e) {
  var file = $('#input')[0].files;
  for (var i = 0; i < file.length; i++) {
    console.log("file_" + i, file[i].name);



  }

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="file" id="input" name="input" multiple="">

Try this way

guradio
  • 15,524
  • 4
  • 36
  • 57