I have a input element of type file. I am binding a change event to the element on document.ready to perform a function once a file is selected. This works quite well in IE 9+ and Chrome.
However, I have users on IE 8 as well. In IE 8 the event fires the first time and then on all subsequent attempts to select a file the event does not fire. I tried clearing the file name, and that did not seem help.
Hopefully I don't have the do a browser check and if it is IE 8, bind the event after every file selection.
I have this set up on jsfiddle:
http://jsfiddle.net/sanpopo/pjH5p/
<input id="fileToUpload" type="file" name="fileToUpload" />
$(document).ready(function () {
addEventToBrowseFileBtn();
alert('event was bound');
});
function addEventToBrowseFileBtn() {
$('#fileToUpload').live('change', function () {
if ($('#fileToUpload').val() == "") {
return false;
}
alert('doing some code stuff');
});
};
Any input advice would be helpful. Thanks!
After doing more research based on some of the comments, I found this post in SO: jQuery change event on <select> not firing in IE looks like the change event has issues with event delegation in IE. All the other solutions I found for input type file suggest using browser detection which I want to avoid.