2

I'm trying to call OnClick() on a file input field but the window for selecting the file doesn't appear. I tried the same on Chrome and Edge and it works perfectly.

var input = document.createElement('input');
input.setAttribute('id', 'InputField');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');

input.style.visibility = 'hidden';
input.onclick = function() {
  console.log('File loading clicked');
};
input.click()

PS: in the 'duplicated' i didn't finded any working functions, probably because the answers are from 7 years ago.

Nicot3
  • 21
  • 2

0 Answers0