0

I am trying to build a custom drag drop and file upload. My div container is empty. Upon drop file i am '' an '' type file into the container and want to trigger its file attachment functionality. my code is not working properly . kindly advice or guide. your favour will be appreciated.

following is my code

<div class="drag" ondrop="drop(event)" ondragover="allowDrop(event)">

function allowDrop(event) {
        event.preventDefault();
    }
    function addinputfile(){
        $('.drag').append('<div class="upload"><input type="file" name="ufile[]" id="ufile" multiple></div>');
    }

    function drop(event) {
        event.preventDefault();
        console.log('something dropped here!');
        addinputfile();
        $('#input#ufile').trigger("click");
    }

code is simply adding '' file type and hitting it to use for file upload.

John Paul
  • 73
  • 10

1 Answers1

1

Actually, some browsers won't allow event trigger on the input: file, Click event will work only, when it comes directly from the user.

But alternative is there to do this, refer it here Jquery trigger file input

Community
  • 1
  • 1
srinath
  • 54
  • 4