Powered By Blogger

Thursday, April 16, 2015

accept only *.xls and *.xlsx file in input type file

<script type="text/javascript" language="javascript">
function checkfile(sender) {
    var validExts = new Array(".xlsx", ".xls");
    var fileExt = sender.value;
    fileExt = fileExt.substring(fileExt.lastIndexOf('.'));
    if (validExts.indexOf(fileExt) < 0) {
      alert("Invalid file selected, valid files are of " +
               validExts.toString() + " types.");
      return false;
    }
    else return true;
}
</script>
 
<input type="file" id="file"  önchange="checkfile(this);" />

No comments:

Post a Comment