/    Sign up×
Community /Pin to ProfileBookmark

Firefox fires on choose, not on change

Consider this:

[CODE]<input type=”file” id=”filePicker”>
<script>
document.getElementById(‘filePicker’).onchange = function() {
alert(‘Hi!’);
};
</script>[/CODE]

Even if you choose the same file and the [FONT=Verdana]filePicker[/FONT] value doesn’t change, you’ll see the alert box in Firefox. Any solutions?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@benmartin101Dec 14.2015 — try:

[CODE]
document.getElementById('filePicker').addEventListener("change",function(){
alert("hello");
});
[/CODE]


Edit: nevermind, I didn't read your question correctly.
Copy linkTweet thisAlerts:
@xelawhoDec 17.2015 — I guess you would have to maintain a reference to a file that has already been chosen (if one exists) and if they choose the same one again do (or not do) whatever it is that you had in mind
Copy linkTweet thisAlerts:
@dan12345Dec 17.2015 — Worked in jsfiddle: https://jsfiddle.net/ktyb4n63/7/embedded/result/

i have an older version of firefox though

[CODE]

<script>
var lastFile = "";
var file;
//var fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();

//file = document.getElementById('filePicker');
//alert(file.value);
//var f = new file(document.getElementById('filePicker'));
var filePicker = document.getElementById('filePicker');
filePicker.onchange = function() {
//ile = document.getElementById('filePicker').value;
file = filePicker.value;

if( !(file === lastFile))
alert('hi');


//alert(file);

lastFile = file;


};
</script>

[/CODE]
Copy linkTweet thisAlerts:
@Rain_LoverauthorDec 17.2015 — Yes, it works. Thanks!
×

Success!

Help @Rain_Lover spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Marika,
tipped: article
amount: 1000 SATS,

tipper: @hatem774,
tipped: article
amount: 1 SATS,

tipper: @nearjob,
tipped: article
amount: 1000 SATS,
)...