2

I am building an image-upload feature into a web application and am using the following event handler:

$('input:file').change(function(){
    //handle input change
});

I have discovered that the handler is not called if I try to upload the same image twice, which makes sense because technically the input is not changing. But I am wondering, what needs to happen in order for the change to be triggered? Here are some examples of what I am looking for:

  • Change of filename
  • Change of file content regardless of filename
  • Change of filetype

Which of these would cause a file to be received as a changed file? Or are there other scenarios as well?

1
  • 1
    Filesize? File modified date? Extension? Commented Jun 16, 2014 at 14:13

1 Answer 1

5

Refer this Link.

Input type - File :

The onchange event is fired when the contents have changed. If the user types the path (does not use the Browse button) in Internet Explorer, then the onchange event is fired only when the element loses the focus. Therefore use the onpropertychange event to detect the modification in Internet Explorer.

MSDN reference

Fires when the contents of the object or selection have changed.

My test results :

  1. Change of filename : Change fires.
  2. Change of content : Keep the filename same, Change event does not fire.
  3. Change of filetype : Keep the filename same, Change fires.
  4. In IE 9,10, if you try to change the filename(in the input field), the change event is fired and the filename field is cleared.

So, moral of the story is, by content change they mean filename change.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks @shaunakde, I didn't expect such a comprehensive and tested answer so quickly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.