mikemaccana
mikemaccana

Reputation: 123178

Why do 'input' events not fire on file inputs, but 'change' events do?

Testing a simple input:

<input type="file"/>

The input event does not fire when a new file is selected:

$('input').on('input', function(event){
    console.log('input value changed', event.target.value)
})

http://jsfiddle.net/baLn0sfy/

The change event fires:

$('input').on('change', function(event){
    console.log('input value changed', event.target.value)
})

http://jsfiddle.net/fzegLugd/

Why doesn't the 'input' event fire?

Upvotes: 0

Views: 70

Answers (2)

Ali Habibzadeh
Ali Habibzadeh

Reputation: 11558

The supported elements for the input event are limited to textArea, input type=text, or input type=password. From MSDN:

Input event occurs when the text content of an element is changed through the user interface.

You can use the oninput to detect when the contents of a textArea, input type=text, or input type=password have changed. This event occurs immediately after modification, unlike the onchange event, which occurs when the element loses focus.

Upvotes: 0

j08691
j08691

Reputation: 207901

According to the W3.org, for a file input, "The input event does not apply." (see the last bullet under bookkeeping details).

Upvotes: 1

Related Questions