Home
> Uncategorized > Convert text to a HTML table
Convert text to a HTML table
Here is a handy litte script that converts tabulated text into a HTML table. Apply a CSS stylesheet to it, and it’ll look nice too …
<textarea id="input" cols=100 rows=10>
</textarea><br>
<input type="button" id="Tabelize" onclick="tabilize()" value="tabilize">
<div id="output"></div>
<script language="javascript">
function tabilize()
{
var input = document.getElementById("input");
var output = document.getElementById("output");
var splitInput = input.value.split("\n");
var html = "<table>";
for(i in splitInput)
{
if (i % 2 == 0)
{
html += "<tr>";
}
else
{
html += "<tr>";
}
var splitRow = splitInput[i].split("\t");
for(j in splitRow)
{
html += "<td>" + splitRow[j] + "</td>";
}
html += "</tr>";
}
html += "</table>";
html = html.replace(/</g,"<");
html = html.replace(/>/g,">");
output.innerHTML = html;
}
</script>
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback