I am developing a system where in A user uploads a image and the JS checks whether minimum width is more than 75 or not.
When we first time upload the file, it alerts a BLANK one. On selecting a next file it alerts the result for the file which was selected before, let me explain below.
- FIrst I select a Image with width more than 200px, it alerts BLANK / Null / No Data.
- When i then select a Image with less than 200px, ideally it should alert false, but it alerts true ( The result for the file selected before).
- Now to reverify the problem, I select a Image with more than 200px, ideally it should alert false, but it alerts false ( The result for the file selected before).
Can anyone clear this mess? I tried googling but didnt help.
My HTML
<input type="file" id="file" />
My JS :
var _URL = window.URL || window.webkitURL;
var wid;
$("#file").change(function(e) {
var file, img,hei;
if ((file = $('#file').prop('files')[0])) {
img = new Image();
img.onload = function() {
wid = ((img.width) > 200) ? true:false;
};
img.onerror = function() {
alert( "not a valid file: " + file.type);
};
img.src = _URL.createObjectURL(file);
}
alert(wid);
});