0

I'm a beginner at Javascript and I would like to build a Web application (html, css and JS). This application allows you to add a .html file (which contains a table with a defined class inside).

I managed to make the input and load it into the Javascript but then I can't get the table into the .HTML file The file seems to be in "blob" format ??? The goal is to display the table in my index.html and then style it.

<p>Depot du fichier d'identification :</p>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
<p></p>


<script src="script.js"></script>
// file recuperation (script.js)
const fileInput = document.getElementById('myfile');
fileInput.onchange = () => {
    const selectedFile = fileInput.files[0];
    console.log(selectedFile);
    const table = fileInput.getElementsByClassName("identification");
    console.log(table);
}

Thank you in advance.

  • Oops, sorry, wrong dupetarget for the reading the file part initially. I've fixed it, the correct one is [this one](https://stackoverflow.com/questions/3146483/html5-file-api-read-as-text-and-binary). Then [this question's answers](https://stackoverflow.com/questions/3103962/converting-html-string-into-dom-elements) tell you how to parse that HTML so you can get at the table inside. – T.J. Crowder Jan 18 '22 at 08:12
  • 1
    I don't think you can like this? HTML usually needs to be parsed by a browser first. --- Ah. TJ Crowder to the rescue again https://stackoverflow.com/questions/3103962/converting-html-string-into-dom-elements – evolutionxbox Jan 18 '22 at 08:37
  • @ Matthieu - My answer to the question about how to read the contents had become outdated, I've updated it. – T.J. Crowder Jan 18 '22 at 08:38
  • Thank you very much ! I did it and know my blob is converted to a string but when I want to do a DOMparse, I see in the console undefined – Matthieu Benard Jan 18 '22 at 10:31
  • @MatthieuBenard that's a new question – evolutionxbox Jan 18 '22 at 10:42

0 Answers0