Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input file onchange event not being fired in chrome

This is a weird thing i noticed in chrome. if the user select a file and then select the same file again bu opening the file dialog again, chrome doesn't fire the onchange event while firefox does.

anybody noticed it as well?

like image 668
Amir Avatar asked Jul 08 '11 10:07

Amir


People also ask

How do I use Onchange input tag?

Definition and UsageThe onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.

What triggers Onchange event?

The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.

What is a Onchange event handler?

The Onchange Event Handler in Javascript is an event handler that is triggered when a user changes something within a form element. An example of this is a drop-down selection menu, where a user selects a new option from a list of choices.


1 Answers

This is a known feature of Chrome and a quick Google on the topic will bring up some interesting discussions.

It makes sense to me that the change event wouldn't fire since nothing has changed (you're selecting the same file)

As for your question, what exactly are you asking? Are you looking for a way to change this behaviour or do you just want to know if we've noticed this as well?

If you want a way around this behaviour you can simply create a new file input in your Javascript and replace the previous one. This way your change event is guarenteed to fire.

like image 181
Jamie Dixon Avatar answered Sep 21 '22 13:09

Jamie Dixon