views:

76

answers:

2

I am unable to detect when input type="file" changes its value after user selects file and the dialog box closes.

$('.myInput').change(function(){
    alert($(this).val());
})

Above jQuery code works perfectly in all browsers apart from IE. For some reason IE detects the change only after input field loses focus.

Is there a way to detect the change immediately after dialog box closes? Or maybe to force input field to lose focus after dialog box closes so IE can detect it?

I'm puzzled. Thanks for any help.

A: 

Edit - Nick is right, it's fixed in 1.4.2. http://jsfiddle.net/7wR2L/

You can detect click and keep track of it's last value. Something like..

$('.myInput').click(function() {
   var $file = $(this);
   if( $file.val() != $file.data('lastVal') ) {
     // different
   }
   $file.data('lastVal', $file.val() );
});
Dan Heberden
Thanks for your help! 1.4.2 works as expected.
ecu
+1  A: 

This was a known bug that was resolved as part of the jQuery 1.4.2 release, 1.4.2 got a major event model re-write and this was fixed as part of that, just upgrade to resolve the problem :)

Nick Craver