Read the contents of uploaded file

Read the contents of the uploaded file

by Varun Krishna P

HTML

<input type="file" onchange="onFileSelected(event)">
<br>
<textarea id="result" rows="10" cols="50"></textarea>

JavaScript

//https://stackoverflow.com/questions/23723769/read-and-display-the-text-file-contents-upon-click-of-button-using-javascript
function onFileSelected(event) {
  var selectedFile = event.target.files[0];
  var reader = new FileReader();

  var result = document.getElementById("result");

  reader.onload = function(event) {
    result.innerHTML = event.target.result;
  };

  reader.readAsText(selectedFile);
}