Firefox fires on choose, not on change

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?

A bit out of my depth here but how about checking the filename?

e.g.

<input type="file" id="filePicker">
<script>
 (function(){
	 var theFileName = document.getElementById("filePicker").value;
	
	  document.getElementById('filePicker').onchange = function() {
        var newFileName = this.value;
				//alert(newFileName + " ...." + theFileName);
				if (newFileName == theFileName){
						alert('Same Filename');	
					} else {
						alert('New Filename');	
				}
				theFileName = this.value;
    };
	 }());   
</script>

There’s probably a better way though :smile:

1 Like

Yes, it works!. Thanks! :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.