0

So I have a input type="file" in my html and a change EventListener which works properly. I now added a remove button which basically works like this:

function removeFile(){
                            document.getElementById("fileinput").value = "";
                        }

Simply setting the value of the file input to an empty string. But this does not trigger the event listener. How can I make this work?

Thanks, Johannes

Johannes
  • 11
  • 2

1 Answers1

0

run ok

function removeFile(){
                            document.getElementById("fileinput").value = "";
                        }
                        
  document.querySelector('#btn1').addEventListener('click', function(){
    removeFile()
  })
<input type="file" name="" id="fileinput">
<button onclick="removeFile()">removeFile</button>
<button id="btn1">removeFile</button>
ebyte
  • 1,469
  • 2
  • 17
  • 32