Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:05:43+00:00 2026-06-18T12:05:43+00:00

I am new to javascript and am trying to read a file and display

  • 0

I am new to javascript and am trying to read a file and display it contents on browser.

I have this code so far:

<script type="text/javascript">
        var fname ;
        if(navigator.appName.search('Microsoft')>-1) { fname = new ActiveXObject('MSXML2.XMLHTTP'); }
        else { fname = new XMLHttpRequest(); }

        function read(filename) {
            fname.open('get', filename, true);
            fname.onreadystatechange= steady;
            fname.send(null);
        }

        function steady() {
            if(fname.readyState==4) {
                var el = document.getElementById('read_file');
                el.innerHTML = fname.responseText;
            }
        }
    </script>

But the output on I get is :

x   y 5 90 25   30 45   50 65   55 85   25

Whereas the data is in format:

 x    y
 5    90
 25   30   
 45   50   
 65   55 
 85   25

Two questions:

1) How do i display it in the format as above

2) As of now, this happens when I click on a button.. is there any way I can automatically read from this given file rather than clicking on a button

SO this is how my html code looks like

<input type="button" value="load file"  onclick="read('data.tsv')">

I want to get rid of this “onclick” and just read the file

THanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:05:44+00:00Added an answer on June 18, 2026 at 12:05 pm

    To remove the button, just add the call to the end of your JavaScript:

        // ...
    
        read('data.tsv');
    </script>
    

    There are a couple of ways to display the data as you find it in the file.

    The first is to wrap it in an element that preserves white-space…

    el.innerHTML = '<pre>' + fname.responseText + '</pre>';
    

    Or you could replace all the line breaks and tabs / spaces with HTML, for example a line break could be converted into a <br> tag and a space could be replaced with a non-breaking space: &nbsp;.

    You could even split it by line-breaks and white-space in order to display it in a table, which would be the correct way of displaying the type of information you have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a text file using JavaScript and display the content
I have some simple text file. I am trying to read that file contents
I am trying to create a new Element in my javascript code and append
I am new to PHP and JavaScript development, I am trying to execute this
I am new to javascript and node, and have been trying to create an
I am new to javascript and have some data stored in a txt file
I'm trying to read the contents of a bunch of javascript files on a
I am trying to load a text file into my JavaScript file and then
i am trying to read the xml file but somehow i am getting this
I am trying to read a file type that has a mixture of integers,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.