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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With