and j...">

JQuery change event not working

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 that the change function only works when the file selection differs from the one selected earlier. This, of course, is the meaning of the change event. I want my function to be called with closing the file dialog box. No matter what.

I tried using the select event - it never gets called

I also tried:

 $(':file').bind('dialogclose', function(event) { alert('closed'); }); 

and

 $(':file').live("dialogclose", function(){ alert('closed1'); }); 

They did not work either.

+4
source share
3 answers

try using this code.

 $('#fileupload').on('change', function () { alert('Hi'); //do your function. }); 

this function will be called only by you otherwise select different files.

+4
source

I know this is an old post, but try using 'input' instead of 'change'. Worked for me. :)

 $('#fileupload').on('input', function () { alert('Hi'); }); 
+4
source

I came across the same problems when working with jQuery dynamically added HTML code.

I would suggest you use the solution below

 $(document).on('input','#fileupload', function () { console.log('Your Code') }); 
0
source

Source: https://habr.com/ru/post/1481982/


All Articles