Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input file only be .xls file [duplicate]

I am working on html and java script. I have file type input with that i want that the input file should only be .xls file

 <input type='file' id ="browse" name ="browse"/>

Now I want that the selected files only be .xls file ..and read that xls file. how to do that with java script...And if someone can explain me with the JavaScript code that will be more appreciated.

like image 602
user2502227 Avatar asked Jun 20 '13 14:06

user2502227


1 Answers

This will check the file extension after choosing a file. If it is not .xls, then it throws an alert error:

document.getElementById("browse").onchange = function() {
    var fileName = this.value;
    var fileExtension = fileName.substr(fileName.length - 4);

    console.log(fileExtension);
    if (fileExtension != ".xls") {
        alert("That ain't no .xls file!");
    }
}

Demo: http://jsfiddle.net/sn5sY/

like image 112
tymeJV Avatar answered Sep 30 '22 05:09

tymeJV