Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript error on IE8 and IE9

I'm getting 'this.0.files.0' is null or not an object error on IE8 and IE9 and Chrome and Mozila don't throw any errors .

$(function()) {
    var fileType = ['txt' , 'csv' ];
    $('.input_file').find('input [type = "file" ]').live('change', function (e)) {
        $this = $(this) 
        var ext = $this.val() === " " ? " " : this.value.match(/\.(.+)$/)[1];
        if($this.val()) {
            $this.parent().find('label').text.($this[0].files[0].name)  
        }
    }
}

Im not sure why above code throws a javascript error 'this.0.files.0' is null or not an object

like image 838
ronan Avatar asked Apr 27 '13 18:04

ronan


1 Answers

IE < 10 has no support for the html5 fileapi, i.e. no HTMLInputElement.FileList you'll have to parse HTMLInputElement.value to get the file name.

like image 131
Musa Avatar answered Sep 20 '22 23:09

Musa