1

Im using a jquery ajax file upload: http://jquery.malsup.com/form/#getting-started

<input type="file" id="foo" name="foo" />

My problem is that the jquery change event does not fire:

$('#foo').change(function(){
    console.log('change');
});

Ive tried using the on('change', function(){ }) method as well, without success.

Any help is appreciated. Thanks

Johan
  • 35,120
  • 54
  • 178
  • 293
  • Does not fire in which browsers? Did you look at [2133807](http://stackoverflow.com/questions/2133807/alternate-to-onchange-event-in-input-type-file)? – h0tw1r3 Feb 26 '12 at 18:44
  • I did the test in firefox. @Ktash I suppose it has something to do with the plugin – Johan Feb 26 '12 at 18:48
  • What is it you are accomplishing with this plugin? A lot of the features it adds (like `serialize`) are standard in the latest jQuery. Also, since I deleted my comment, the [test case](http://jsfiddle.net/NnMKg/) again. – LoveAndCoding Feb 26 '12 at 18:51
  • Check again and check out this fiddle and it works. http://jsfiddle.net/A8XP3/ – mcometa Feb 26 '12 at 18:52
  • @mcometa your fiddle doesn't use the file upload plugin, I think that is causing the problem. Change event is triggered normally without it. – Tx3 Feb 26 '12 at 20:50
  • @Johan could you provide a jsfiddle example of the problem? – h0tw1r3 Feb 26 '12 at 20:53

2 Answers2

0

Try this. Dont know if its bad to use .live, but works for me, when the normal way dosnt

$('#foo').live('change',function(){
    alert('change');
});
Lasse
  • 651
  • 2
  • 8
  • 24
0

It might that your problem is in the order of the bindings.

Here is a jsFiddle that I used for testing. I have linked the plugin to this solution and it seems that the change event is triggered only if binding is done before .ajaxForm.

Let me know if this doesn't solve your problem.

Tx3
  • 6,796
  • 4
  • 37
  • 52
  • Actually [it works either way](http://jsfiddle.net/NdVyJ/4/) for me (tested in Chrome and FF 9), but I had to fix the forms url. – h0tw1r3 Feb 26 '12 at 21:02