i made a drag and drop over the whole page. Now if i drop a file (.txt) i want to get the filename and the filepath and filename should be put in the "input"-Box (id: fileUpload) but unfortunately i don't know how to solve this. DragNDrop works!
//JavaScript
var dropZone = document.getElementById('dropzone');
function showDropZone() {
dropZone.style.display = "block";
}
function hideDropZone() {
dropZone.style.display = "none";
}
function allowDrag(e) {
if (true) { // Test that the item being dragged is a valid one
e.dataTransfer.dropEffect = 'copy';
e.preventDefault();
}
}
function handleDrop(e) {
e.preventDefault();
hideDropZone(this);
alert('File was dropped');
}
// 1
window.addEventListener('dragenter', function (e) {
showDropZone();
});
// 2
dropZone.addEventListener('dragenter', allowDrag);
dropZone.addEventListener('dragover', allowDrag);
// 3
dropZone.addEventListener('dragleave', function (e) {
hideDropZone();
});
// 4
dropZone.addEventListener('drop', handleDrop);
//HTML (here i can use the "div" or the "form" as the dropzone)
<div id="dropzone" class="dropzone"></div>
@*<form action="/file-upload" id="dropzone" class="dropzone"></form>*@
<input type="file" id="fileUpload" name=""/>