0

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;
    }
}
2
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by code739
0

I think data.value = null; should work, but it is quite possible that the file input is read-only. If so, the only option remaining is to remove the element entirely, and insert a new one into the DOM.

Edited by pritaeas

1

yah i got your idea =) tnks anyway. You really a posting sage priteas =)..
i also thought of an idea in reseting the form =) like

document.formname.reset()
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.