IE input file attribute is undefined

26,020

Solution 1

This seems good enough...

$(function() {
    var input = $('#handlerxhr1')[0];         
    $('#upload').click(function() {             
        alert(input);          
    }); 
});

Not sure if your were after something like this though:

$(function() {
    var input = $('#handlerxhr1')[0];         
    $('#upload').click(function() {             
        var x = $('input[type=file]:eq(0)');
        alert(x);
    }); 
});

Solution 2

IE doesn't support .files[0] property, whereas FF does. See http://www.w3.org/TR/FileAPI/ for more details

Share:
26,020
ShaneKm
Author by

ShaneKm

I am a .Net software engineer, mentor, thinker, and loud-mouth on the microservices, software architecture, and development of enterprise applications. With over 15+ years of commercial software development experience across a wide range of technologies, I’ve successfully delivered software products for embedded, Windows, and web platforms. I'm a passionate manager and developer always looking for opportunities and challenges with an approach to defining computing and network infrastructure through patterns, SOLID principles, and practices of writing clean and extensible code. In my free time, you can find me exploring the city, at the gym, or reading a book.

Updated on December 08, 2020

Comments

  • ShaneKm
    ShaneKm over 3 years

    I have the following input file tag:

    <input type="file" id="handlerxhr1" />
    

    In mozilla when I run the following jQuery code:

    var input = $('#handlerxhr1')[0];
            $('#upload').click(function() {
                alert(input.files[0]);
    
            });
    

    I get response: [object File] (which is good).

    But in IE I get 'input.files.0 is undefined'

    What am I doing wrong?