Jump to content

Firefox fires on choose, not on change


Rain Lover

Recommended Posts

Consider this:




<input type="file" id="filePicker">
<script>
document.getElementById('filePicker').onchange = function() {
alert('Hi!');
};
</script>



Even if you choose the same file and the filePicker value doesn't change, you'll see the alert box in Firefox. Any solutions?

Link to comment
Share on other sites

Well, why not simply have your code ignore it?

<input type="file" id="filePicker">
<script>
var filename = '';
document.getElementById('filePicker').onchange = function() {
var f = document.getElementById('filePicker').value.trim().toLowerCase();
if (f != filename){
  filename = f; 
  alert('New filename: ' + f);
}
};
</script>
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...