1

I would like to start uploading the files that I have just selected using the input type="file" multiple="multiple" html element.

Which event can I hook into to run code right after the file dialog has closed and I have completed my files selection.

My html code looks like this:

<form enctype="multipart/form-data" action="/photo" method="post">
  <input type="hidden" name="section_id" value="234" />
  <input type="file" multiple="multiple" id="section_photos" name="section_photos[]" accept=".jpg, .png, .gif" />
</form>
1
  • onchange Commented Apr 26, 2018 at 1:28

2 Answers 2

4
$('input[type=file]').change(function (e) {
    console.log(e);
    console.log(e.target.files); //a list of the files
});

for file array, you can select it by type with specific class as well.

    <input type="file" class="fileclassputhere" multiple="multiple" id="section_photos" name="section_photos[]" accept=".jpg, .png, .gif" />

<script>
    $('input[type=file].fileclassputhere').change(function (e) {
      console.log(e);
      console.log(e.target.files); //a list of the files
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

2

Add a change eventListener to the input:

var input = document.getElementById('input')
input.addEventListener('change', function(e){
  console.log(e);
  console.log(e.target.files); // a list of the files
});

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.