| | |
Javascript read text file and create table
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi,
I got a text file ('testdetails2.txt') and my text file looks something like this:
abc123, 234 pqr,xyz "type"
bc123, 234 pqr,xyz "type"
c123, 234 pqr,xyz "type"
n23, 234 pqr,xyz "type"
aj23, 234 pqr,xyz "type"
As you notice, it has got "," aswell a blank space and "". all i wish to to do is preset the contents of the text file in a nice html table.
Please can someone help?
I got a text file ('testdetails2.txt') and my text file looks something like this:
abc123, 234 pqr,xyz "type"
bc123, 234 pqr,xyz "type"
c123, 234 pqr,xyz "type"
n23, 234 pqr,xyz "type"
aj23, 234 pqr,xyz "type"
As you notice, it has got "," aswell a blank space and "". all i wish to to do is preset the contents of the text file in a nice html table.
Please can someone help?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> </head> <script type="text/javascript"> function loadTxtFile(){ .. .. } </script> <body> <div id="T1" style="border:1px solid black;width:300;padding:5"></div><br /> <button onclick="loadTxtDoc('testdetails2.txt')">Click</button> <button onclick="loadTxtDoc('testdetails3.csv')">Click</button> </body> </html>
•
•
Join Date: Nov 2009
Posts: 3
Reputation:
Solved Threads: 0
0
#2 Nov 6th, 2009
Just to test the javascript code, this is what i did, but it says error.
html
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var txt ='abc123, 234 pqr,xyz "type"\nbc123, 234 pqr,xyz "type"\nc123, 234 pqr,xyz "type"\nn23, 234 pqr,xyz "type"\naj23, 234 pqr,xyz "type"' function table_maker(txt){ var rows=txt.split('\n'), r, cells, c, j, i=0; var table='<table>'; while(r=rows[i++]){ table+='<tr>'; cells=r.split(','); j=0; while(c=cells[j++]){ table+=('<td>'+c+'</td>'); } table+='</tr>'; } table+='</table>'; return table; document.getElementById("T1").innerHTML=table; }
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<div id="T1" style="border:0px solid black;width:300;padding:5"></div> <button onclick="table_maker();">Authorisation Checker Error log </button>
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
0
#3 Nov 6th, 2009
<html></head> <script type="text/javascript"> function loadTxtFile(){.... }</script> <body> <div id="T1" style="border:1px solid black;width:300;padding:5"></div><br /> <button onclick="loadTxtDoc('testdetails2.txt')">Click</button> <button onclick="loadTxtDoc('testdetails3.csv')">Click</button> </body> </html><html>
</head>
<script type="text/javascript">
function loadTxtFile(){
..
..
}
</script>
<body>
<div id="T1" style="border:1px solid black;width:300;padding:5"></div><br />
<button onclick="loadTxtDoc('testdetails2.txt')">Click</button>
<button onclick="loadTxtDoc('testdetails3.csv')">Click</button>
</body>
</html>
</head>
<script type="text/javascript">
function loadTxtFile(){
..
..
}
</script>
<body>
<div id="T1" style="border:1px solid black;width:300;padding:5"></div><br />
<button onclick="loadTxtDoc('testdetails2.txt')">Click</button>
<button onclick="loadTxtDoc('testdetails3.csv')">Click</button>
</body>
</html>
![]() |
Similar Threads
- Read text file to a certain point (C#)
- how to read a particular text in a file (C)
- Read text file through console application (VB.NET)
- How do I read a text file into a 2D vector? (C++)
- read text file (C)
- read text file (C#)
- using a "for" loop to read a text file (VB.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: What Do I need to learn AJAX?
- Next Thread: Help...Please!
Views: 704 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child class close codes date debugger dependent developer disablefirebug dom editor element embed engine enter events explorer ext file firefox flash form forms frameworks game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe java javascript javascripthelp2020 jquery jsf jsp jump libcurl maps margin marquee masterpage math media menu object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star stars stretch synchronous toggle tweet unicode variables web webkit webservice window \n





