Hi guys i have a problem here
i have and input type file which will be containing an image file
<input type="file" onchange="validate(this)"/>
now my code below work in its extension detection but if it is invalid the input file still have i value
i want it that if the file is invalid the file that is being browse will not be the value
please see the javascript below:
var _validFileExtensions = ["jpg", "jpeg", "bmp", "gif", "png"];
function validate(data) {
var isvalid = false;
var photo = data.value.toLowerCase();
photos = photo.split(".");
photo = photos[photos.length-1];
for(var x=0;x<_validFileExtensions.length;x++){
if(_validFileExtensions[x]==photo){
isvalid = true;
break;
}
}
if(!isvalid){
alert('Invalid File');
return false;
}
}