jQuery change method on input type="file"
is the ajax uploader refreshing your input element? if so you should consider using .live() method.
$('#imageFile').live('change', function(){ uploadFile(); });
update:
from jQuery 1.7+ you should use now .on()
$(parent_element_selector_here or document ).on('change','#imageFile' , function(){ uploadFile(); });
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). Refer: http://api.jquery.com/on/
$('#imageFile').on("change", function(){ uploadFile(); });
I could not get IE8+ to work by adding a jQuery event handler to the file input type. I had to go old-school and add the the onchange=""
attribute to the input tag:
<input type='file' onchange='getFilename(this)'/>
function getFileName(elm) {
var fn = $(elm).val();
....
}
EDIT:
function getFileName(elm) {
var fn = $(elm).val();
var filename = fn.match(/[^\\/]*$/)[0]; // remove C:\fakename
alert(filename);
}