Skip navigation

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

1737 Views 3 Replies Latest reply: Feb 8, 2012 4:29 AM by ra5ul RSS
benedicke Level 1 Level 1 (0 points)
Currently Being Moderated
Feb 7, 2012 2:02 AM

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)


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.