title: Read text file using FileReader
body: <p>I've written the following code in an attempt to read the contents of a .txt file</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;input type="file" id="files" name="file" /&gt;
  &lt;div id="container" style="height: 500px; min-width: 500px"&gt;&lt;/div&gt;
  
  &lt;script&gt;
      function handleFileSelect(evt) 
      {
          var files = evt.target.files; // FileList object
  
          // Loop through the FileList and render image files as thumbnails.
          for (var i = 0, f; f = files[i]; i++) 
          {
  
              var reader = new FileReader();
              reader.onload = (function(theFile) 
              {
                  var contents = theFile.target.result;
                      var lines = contents.split('\n');
  
              })(f);
  
              reader.readAsText(f);
          }
      }
  
    document.getElementById('files').addEventListener('change', handleFileSelect, false);
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Using firebug I set a break on <code>var contents = theFile.target.result;</code> but nothing is being returned. Can anyone spot what's wrong?</p>
  
  <p>Thank you</p>