Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix Cannot set properties of null (setting 'innerHTML') at HTMLInputElement.loader

Can someone please help with this code I know that everything is correct but it still doesn’t work for some reason if you read the title it gives me that error when I try to use it. I tried to modify my code multiple times but it still doesn’t work if you guys have any ideas on how to fix it please help me. Thank you:)

let loader = function(e) {
  let file = e.target.files;

  let show = "Selected File: " + file[0].name;

  let output = document.getElementById("selector");
  output.innerHTML = show;
  output.classList.add("active");
};

let fileInput = document.getElementById("file");
fileInput.addEventListener('change', loader);
<input type="file" accept="video/* image/*" multiple name="" id="selector" hidden>
<label for="file" class="upload" id "selector"> Select a file: </label>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

first, typo issue: id = "selector" in the <label> (missing "=") like the example below to select a file:

<input type="file" id="file-selector" multiple>
<script>
  const fileSelector = document.getElementById('file-selector');
  fileSelector.addEventListener('change', (event) => {
    const fileList = event.target.files;
    console.log(fileList);
  });
</script>

Code above displays the name of the file selected next to the button:

enter image description here

to limit the file types:

<input type="file" id="file-selector" accept=".jpg, .jpeg, .png">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading