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
Reply

Join Date: Nov 2009
Posts: 3
Reputation: SALMANSOHAIL is an unknown quantity at this point 
Solved Threads: 0
SALMANSOHAIL SALMANSOHAIL is offline Offline
Newbie Poster

Javascript read text file and create table

 
0
  #1
Nov 6th, 2009
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>
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: SALMANSOHAIL is an unknown quantity at this point 
Solved Threads: 0
SALMANSOHAIL SALMANSOHAIL is offline Offline
Newbie Poster
 
0
  #2
Nov 6th, 2009
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>
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: sumeetb27 is an unknown quantity at this point 
Solved Threads: 0
sumeetb27 sumeetb27 is offline Offline
Newbie Poster
 
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>
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: SALMANSOHAIL is an unknown quantity at this point 
Solved Threads: 0
SALMANSOHAIL SALMANSOHAIL is offline Offline
Newbie Poster
 
0
  #4
Nov 6th, 2009
Sumeet, please can you explain again, i can't see any update in your post...
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 706 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC