Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
is there a way to take text from input type file and proccess the text in javascript

i am trying to preview a text from a text file through input type file using javascript i tried using the file directly in my code but error is prompted saying file is undefiend but when i use file.value or print file to console an object from file is displayed

function readInsideFile()
{
         const [file] = document.querySelector('input[type=file]').files;
         console.log(file);
        const reader = new FileReader();
        
    // this will then display a text file
        var text = reader.readAsText(file);
        console.log(text);
         var firstLine = text.split('\n').shift(); // first line 
        
         var sensorsoutputfield = document.getElementById("Rectangle_8_bu");
         sensorsoutputfield.innerHTML = firstLine;
    
    
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes, you can read files, but you must write lambda functions for reader. Use this Example

function readInsideFile()
{
     const files = document.querySelector('input[type=file]').files;
     console.log(files);
     const reader = new FileReader();
     // this will then display a text file
     reader.onload = () => {
         var content = reader.result;
         console.log(text);
         var firstLine = text.split('\n').shift(); // first line
         var sensorsoutputfield = 
         document.getElementById("Rectangle_8_bu");
         sensorsoutputfield.innerHTML = firstLine;
     }
     reader.readAsText(this.files[0]);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!