title: How to display text from a textfile in html with javascript
body: <p>I want to use a text file as source for the text on my website. I just can't display it where I want it to be</p>
  
  <p>I have already managed to read the text from the file, but now I'm stuck.</p>
  
  <p>This is my readFile function:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script&gt;
    function readFile(input){
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 &amp;&amp; this.status == 200) {
          var textFileText = searchFile(this.responseText, input);
          document.getElementById(input).innerHTML = this.textFileText;
        }
      };
      xhttp.open("GET", textFile, true);
      xhttp.send();
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>I've tried it out and it works.</p>
  
  <p>This is the searchFile function:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script&gt;
    function searchFile(text, searched){
      var output;
      var n = text.search(searched);
      output = text.substr((n+str.length+2), text.indexOf('\n'));
      return output;
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>It's supposed to filter the text in the file for a specific word.</p>
  
  <p>The text file looks like this:</p>
  
  <pre><code>[header]=text
  [thing1]=more text
  </code></pre>
  
  <p>My idea is that if I call the function like this:</p>
  
  <pre><code>readFile("thing1");
  </code></pre>
  
  <p>The output should be "more text"</p>
  
  <p>Here I call the function to display the header Text:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;h2 onload = "readFile(this.id)" id = "header"&gt;&lt;/h2&gt;
  </code></pre>
  
  <p>But then nothing gets displayed.</p>
  
  <p>I've also tried this:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;h2 onload = "readFile('header')" id = "header"&gt;&lt;/h2&gt;
  </code></pre>
  
  <p>But again nothing is displayed.</p>
  
  <p>Am I missing something or did I do something wrong?</p>