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.

4
  • you loop through them using for loop Commented Feb 5, 2016 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 Commented Feb 5, 2016 at 10:20
  • Possible duplicate stackoverflow.com/questions/3654179/… Commented Feb 5, 2016 at 10:23
  • stackoverflow.com/questions/7023457/… Commented Feb 5, 2016 at 10:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.