Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How to determine the drop zone for a multi drag-and-drop file uploader?

Question

How do I accurately determine which drop zone the file was dropped into?

Background

I'm creating an HTML page with vanilla JavaScript that has 2 drop zones for 2 different file types, and depending on which drop zone the file is sent to, the files should ultimately be sent to a different endpoint.

Drop Zone HTML

  <div class="drop-area" id="drop-area-1" >
    <form class="my-form" id="form-1">
      <p id="p-1">Drop Area 1</p>
    </form>
  </div>

  <div class="drop-area" id="drop-area-2" >
    <form class="my-form" id="form-2">
      <p id="p-2">Drop Area 2</p>
    </form>
  </div>

Javascript

I won't put in all the boilerplate stuff like preventDefaults, but I'll show the drop handler function

  function handleDrop(e) {
    var dt = e.dataTransfer;
    var files = dt.files;
    let fileType = e.target.innerText;
    handleFiles(files, fileType)
  }

Problem

Depending on if I release the drag in the div, the form, or the p, I get different values for e.target.id

For example, if I add a console.log(e.target.id), I can get the following values depending on where I do the actual drop:

  • drop-area-1 / drop-area-2
  • form-1 / form-2
  • p-1 / p-2

So what value in the event can I use to say regardless of where the drop occurs that it happened in drop?

Current solution

The only way I've managed to get it to work consistently is by using e.target.innerText which feels like a hack.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!