View Full Version : Firefox fires on choose, not on change
Rain Lover
12-14-2015, 01:55 PM
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?
coothead
12-14-2015, 06:15 PM
Hi there Rain Lover,
would this possibly meet your requirements...
<script>
var temp;
document.getElementById('filePicker').onchange = function() {
if(this.value==temp){
return;
}
else {
temp=this.value;
alert('Hi!');
}
};
</script>
coothead
Rain Lover
12-15-2015, 04:35 AM
Thanks for the answer, but would you mind teaching me something: I don't understand return. What does it do in JavaScript? Does it mean "Do nothing"?
coothead
12-15-2015, 10:19 AM
Hi there Rain Lover,
unfortunately, teaching is not my forte perhaps our resident guru...
"jscheuer1" (http://www.dynamicdrive.com/forums/member.php?2033-jscheuer1)
...could help. ;)
Alternatively, you could try this...
javascript "return" information (https://www.google.co.uk/search?q=javascript+return)
Note though, that it could have been coded without it like this...
<script>
(function() {
'use strict';
var temp;
document.getElementById('filePicker').onchange = function() {
if(this.value!==temp){
temp=this.value;
console.log('Hi!'); /* instead of alert('Hi!'); */
}
};
})();
</script>
coothead
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.