title: Load a file automatically without using a click button
body: <p>I am new to javascript and want to load the file without having to click on the load file button</p>
  
  <p>I am using the following script and I want the text to be loaded automatically in the text box.</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Select a File to Load:&lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="file" id="fileToLoad"&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;button onclick="loadFileAsText()"&gt;Load File&lt;/button&gt;
                  &lt;td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="3"&gt;
                      &lt;textarea id="inputTextToSave" style="width:512px;height:256px"&gt;&lt;/textarea&gt;
                  &lt;/td&gt;&lt;/tr&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;script type='text/javascript'&gt;
  function loadFileAsText()
  {
      var fileToLoad = document.getElementById("fileToLoad").files[0];
      var fileReader = new FileReader();
      fileReader.onload = function(fileLoadedEvent) 
      {
          var textFromFileLoaded = fileLoadedEvent.target.result;
          document.getElementById("inputTextToSave").value = textFromFileLoaded;
      };
      fileReader.readAsText(fileToLoad, "UTF-8");
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks in advance for the help.</p>