javascript read file from disc 1

javascript read file from disc

function readSingleFile(e) {
  var file =[0];
  if (!file) {
  var reader = new FileReader();
  reader.onload = function(e) {
    var contents =;

function displayContents(contents) {
  var element = document.getElementById('file-content');
  element.textContent = contents;

  .addEventListener('change', readSingleFile, false);

Here is what the above code is Doing:
1. When the user clicks the “Choose File” button, the file chooser pops up.
2. When the user selects a file, the onchange event triggers, and the readSingleFile function is executed.
3. The readSingleFile function is passed a reference to the file.
4. The readSingleFile function reads the file and displays its contents in the textarea.

Similar Posts