Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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)

Posted on Feb 7, 2012 2:02 AM

Reply
Question marked as Best reply

Posted on Feb 7, 2012 4:37 PM

i'm pretty sure this was fixed along with bug 63929 (https://bugs.webkit.org/show_bug.cgi?id=63929). onchange fired consistently when i tested a recent webkit nightly build.

3 replies

JavaScript: input type="file" does not fire change event

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.