#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0

    Document.getElementById not working in IE9


    Hi guys,

    I Hope you can help with this.

    Code:
    file = document.getElementById('fileToUpload').files[0];
    This is working fine in Chrome and MF browsers, but doesn't in IE8. I get the error:
    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Timestamp: Fri, 18 Jan 2013 18:13:52 UTC


    Message: 'document.getElementById(...).files.0' is null or not an object

    Why?


    Thx..
    Kr,
    C.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0
    I think it's OK now. I removed that (.files[0]), and then it works.

    But I still can't display the content of the file.

    In chrome, for example:
    Code:
    file.files[0].name;
    works fine!! In IE8 not!

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Are you using the onload event?
    Code:
    window.onload = function() {
    //Your JavaScript code here.
    }
    Also, could you try and explain a little better what you are trying to do?
  6. #4
  7. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,009
    Rep Power
    2791
    You cannot access the file, it would be (and was for a short time) a huge security hole in browsers. The only thing you can do is read the file name.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0
    IE does not support Data Forms at all; I tried all possible ways I know and no way I can upload a txt using ajax instead of submit.

IMN logo majestic logo threadwatch logo seochat tools logo