Cancel selection of Uploads

Asked

Viewed 162 times

5

I’m trying to upload files imagens, but when I’m clicking on X of the photo Preview, it is only closing the Preview, but it is still selected. How can I do for when click on x, also take that image from the list?

My JS code just below.

    <script>
 window.onload = function(){

    //Check File API support
    if(window.File && window.FileList && window.FileReader)
    {
        var filesInput = document.getElementById("files");

        filesInput.addEventListener("change", function(event){

            var files = event.target.files; //FileList object
            var output = document.getElementById("result");

            for(var i = 0; i< files.length; i++)
            {
                var file = files[i];

                //Only pics
                if(!file.type.match('image'))
                  continue;

                var picReader = new FileReader();

                picReader.addEventListener("load",function(event){

                    var picFile = event.target;

                    var div = document.createElement("div");

                    div.innerHTML = "<img class='thumbnail' src='" + picFile.result + "'" +
                            "title='" + picFile.name + "'/> <a href='#' class='remove_pict del'><i class=\"icon-remove\"></i></a>";

                    output.insertBefore(div,null);   
                    div.children[1].addEventListener("click", function(event){
                       div.parentNode.removeChild(div);
                    });         

                });

                 //Read the image
                picReader.readAsDataURL(file);
            }                               

        });
    }
    else
    {
        console.log("Your browser does not support File API");
    }
}
</script>
  • Have you tested with files.value = '';?

  • I didn’t test it, but how would it look ? @Sergio

  • Renan, which list you say should be taken too?

  • ?? does not understand your question.

  • Of your question: How can I do it when I click on x that image of list? - Which list you mean? (Remark outside the scope: When replying to a comment, put @nameDoUsuario, so it is notified of its replica: in my case it would be @falsarella).

  • Is java or javascript?

  • javscript. @Guilhermenascimento porem ja solucionei.

  • 1

    Renan then formulate a response, it can be useful to other users.

  • Okay I’ll formulate, as soon as I get back to working on this project.

Show 4 more comments

1 answer

2


Try the excerpt from the event where you remove the image:

div.children[1].addEventListener("click", function(event){
    div.parentNode.removeChild(div);
    filesInput.value = '';
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.