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?

<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>

Just to test the javascript code, this is what i did, but it says error.

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;
}

html

<div id="T1" style="border:0px solid black;width:300;padding:5"></div> 
<button onclick="table_maker();">Authorisation Checker Error log </button>

<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>

Sumeet, please can you explain again, i can't see any update in your post...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.