Reputation: 2150
I have html:
<form id="fileuploadform">
<input type="file" id="fileupload" name="fileupload" />
</form>
and jquery:
$(':file').change(function(){
var file = this.files[0];
...
});
The problem is: the change function fires only when the file selection is different than the selection made previously. That is of course the meaning of the 'change' event. I want my function to be called with the file dialog closes, no matter what.
I tried using 'select' event -- it never gets called
I also tried:
$(':file').bind('dialogclose', function(event) {
alert('closed');
});
and:
$(':file').live("dialogclose", function(){
alert('closed1');
});
They didn't work either.
Upvotes: 5
Views: 25543
Reputation: 709
I have faced the same issues when I used to work with jQuery dynamic appended HTML.
I would suggest you to use the below solution
$(document).on('input','#fileupload', function () {
console.log('Your Code')
});
Upvotes: 12
Reputation: 465
I know this is an old post, but try using 'input' instead of 'change'. Worked for me. :)
$('#fileupload').on('input', function () {
alert('Hi');
});
Upvotes: 6
Reputation: 973
try to use this code.
$('#fileupload').on('change', function () {
alert('Hi');
//do your function.
});
this function will call only you select different files otherwise not.
Upvotes: 6