Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:11:50+00:00 2026-06-04T22:11:50+00:00

I will advise you prior that I have limited JavaScript experience. Currently, I have

  • 0

I will advise you prior that I have limited JavaScript experience.


Currently, I have the JavaScript code:

$('#xhr-filebox').bind({
    "dragover": HandleDragEvent,
    "dragleave": HandleDragEvent,
    "drop": HandleDropEvent
});

function HandleDropEvent(e){
    var files = e.target.files || e.dataTransfer.files;
    UploadFile(files[0]);
}

(some code is omitted, but I will add more if you request)

…and the HTML:

<div class="filebox" id="xhr-filebox">
    <p id="xhr-action">...or click me to pick one.</p>
</div>

However, when I drag a file into it, the Chrome JS console says this:

Uncaught TypeError: Cannot read property ‘files’ of undefined

It can however get the FileList object when reading from a file input.

Curiously, when I log the event argument ( console.log(e) ), it logs it as f.event, whereas in a similar script of mine, it logs it as MouseEvent (screenshot: https://i.stack.imgur.com/3krcT.png)

Unlike the bind() function in jQuery, this uses the addEventListener() function of a DOM object returned by getElementById(), IE this is pure JavaScript. I have tried that method but nothing new happens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:11:52+00:00Added an answer on June 4, 2026 at 10:11 pm

    If files doesn’t exist on e.target, you’re looking for a files on e.dataTransfer — but if there’s no dataTransfer property on e (and there doesn’t seem to be in your screenshot) you’ll try to dereference undefined, resulting in this error.

    I’d change the code to:

    function HandleDropEvent(e){
        var files = e.target.files || (e.dataTransfer && e.dataTransfer.files);
        if (files) {
            UploadFile(files[0]);
        }
        else {
            // Perhaps some kind of message here
        }
    }
    

    That way, if e.target.files doesn’t exist and e.dataTransfer also doesn’t exist, you’ll get files being undefined, rather than an error.


    The event object that jQuery gives you is created and normalized by jQuery. Since we know e.dataTransfer doesn’t exist on that event object (from your screenshot), my guess is that it’s not one of the properties jQuery copies over from the original event object. That’s okay, though, because jQuery gives us access to the original event via e.originalEvent. So I’d try:

    function HandleDropEvent(e){
        var dt = e.dataTransfer || (e.originalEvent && e.originalEvent.dataTransfer);
        var files = e.target.files || (dt && dt.files);
        if (files) {
            UploadFile(files[0]);
        }
        else {
            // Perhaps some kind of message here
        }
    }
    

    That grabs files from e.target if that’s where it is, or from the dataTransfer object wherever we find it (on e, or on e.originalEvent).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please advise.. In the following code(Tested. Will work fine) public class Exp_Test { public
Can anyone please advise me if there will be any problems changing the wordpress
Will Java code built and compiled against a 32-bit JDK into 32-bit byte code
Will this code ever wait on the mutex inside the producer's void push(data) ?
I have a service that reads an xml document from a directory(works OK), saves
I wonder if anyone can advise: I have a scenario where a scheduled job
I have a CSV file will 3x10^6 rows, title and body mostly, the text
Let's say I have a text file to commit using Subversion. Prior to commit,
I have this php page that posts to itself and then it checks weather
I have a stored procedure that i thought was caught in an infinite loop,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.