944,087 Members | Top Members by Rank

Ad:
Nov 6th, 2009
0

Javascript read text file and create table

Expand Post »
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?

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. </head>
  3. <script type="text/javascript">
  4. function loadTxtFile(){
  5. ..
  6. ..
  7.  
  8. }
  9. </script>
  10.  
  11. <body>
  12. <div id="T1" style="border:1px solid black;width:300;padding:5"></div><br />
  13. <button onclick="loadTxtDoc('testdetails2.txt')">Click</button>
  14. <button onclick="loadTxtDoc('testdetails3.csv')">Click</button>
  15. </body>
  16. </html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SALMANSOHAIL is offline Offline
3 posts
since Nov 2009
Nov 6th, 2009
0
Re: Javascript read text file and create table
Just to test the javascript code, this is what i did, but it says error.


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var txt ='abc123, 234 pqr,xyz "type"\nbc123, 234 pqr,xyz "type"\nc123, 234
  2.  
  3. pqr,xyz "type"\nn23, 234 pqr,xyz "type"\naj23, 234 pqr,xyz "type"'
  4. function table_maker(txt){
  5. var rows=txt.split('\n'), r, cells, c, j, i=0;
  6. var table='<table>';
  7. while(r=rows[i++]){
  8. table+='<tr>';
  9. cells=r.split(',');
  10. j=0;
  11. while(c=cells[j++]){
  12. table+=('<td>'+c+'</td>');
  13. }
  14. table+='</tr>';
  15. }
  16. table+='</table>';
  17. return table;
  18. document.getElementById("T1").innerHTML=table;
  19. }
html

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <div id="T1" style="border:0px solid black;width:300;padding:5"></div>
  2. <button onclick="table_maker();">Authorisation Checker Error log </button>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SALMANSOHAIL is offline Offline
3 posts
since Nov 2009
Nov 6th, 2009
0
Re: Javascript read text file and create table
<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>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sumeetb27 is offline Offline
1 posts
since Oct 2009
Nov 6th, 2009
0
Re: Javascript read text file and create table
Sumeet, please can you explain again, i can't see any update in your post...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SALMANSOHAIL is offline Offline
3 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: What Do I need to learn AJAX?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Help...Please!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC