JavaScript: input type="file" does not fire change event
I have a very simple form with input type="file" and a listener of onchange event for this field.
Consider the following situation.
1. User selected file A and press "upload" button. I send the file to the server via AJAX.
2. Now I need to clear the file field. I tried different ways to do this:
- set value of input to null or ""
- call "reset" method of the form
- reset innerHtml/outerHtml
- use input type=reset to reset the form
3. Whatever I do the value of the input seem to be clear, but! If I select the same file A in this input "onchange" event will not be fired. This is not convenient because in our case sometimes user will need to do re-upload of the file with the same name.
In other browsers (like Chrome, Firefox) it is enough to set value of input to null to get onchange event fired when we select the same or another file.
In Safari nothing works and it looks like a browser issue.
MacBook Pro, Mac OS X (10.6.7)