0

I need to listen to file select event whenever user selects a file (on repeated clicks of the browse button).

However, if the user selects the same file as previously, the change event does not fire. Is there some other event I could listen to, or other solution to this problem?

(function() {
  $('.file_upload').on('change', function() {
    console.log('Changed!');
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<label class="btn btn-primary">File #1 <input name="file1" id="file1" class="file_upload a1" type="file" /></label>
MTCoster
  • 5,868
  • 3
  • 28
  • 49
dar25
  • 93
  • 12

1 Answers1

1

After you have done your logic for your file upload or whatever you are doing, you can reset the value property.

See this post

var $f1 = $("#container .f1");

function FChange() {
    alert("f1 changed");
    
    $(this).prop("value", "");
}

$f1.change(FChange);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container">
    <input type="file" class="f1">
</div>

Another thing mentioned was that you can actually remove and re add the file input element on change.

Isaac Vidrine
  • 1,568
  • 1
  • 8
  • 20