Reputation: 51
i have an input array to select multiple files.
<input type="file" name="files[]" multiple='multiple'/>
<div id='my_div'>Filenames</div>
How do i get the filenames using jquery? For text types, the map function works
var values=$("input[name='text_string[]']").map(function(){return $(this).val();}).get();
Is there any way to get filenames on clicking div?
Upvotes: 0
Views: 2405
Reputation: 337560
You can access the files
array of the control and then map()
to create an array of the individual file names, something like this:
$('input').on('change', function() {
var filenames = Array.from(this.files).map(function(f) {
return f.name;
});
console.log(filenames);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" name="files[]" multiple='multiple' />
Upvotes: 1