I am new here with very limited knowledge on programming. I just use whatever I find from the web and expirement on them. Let me explain how I meant.
I have a database text file that looks like this.
colh01|colh02|colh03|colh04|colh05|
data11|data12|data13|data14|data15|
data21|data22|data23|data24|data25|
data31|data32|data33|data34|data35|
data41|data42|data43|data44|data45|
Now I used the javascript I found in the web to display the contents to a table.
<script type="text/javascript">
onload = function () {
if (!document.getElementById || !document.getElementsByTagName)
return;
var frm = null,
prenode,
tbod = document.getElementById('tbod'),
data = '';
if ((frm = top.frames['buffer']) //iframe
&& frm.document) { //get <pre> parent
prenode = frm.document.getElementsByTagName('pre').item(0);
if (null != prenode
&& null != prenode.firstChild
&& /#text/.test(prenode.firstChild.nodeName)) //text node
{
data += prenode.firstChild.data; //read
data = data.split(/[\n\r]/); //separate lines
data.splice(0, 0); //lose first two (legend)
var i = 0,
l = data.length, rowdata, ii, ll, tr, td;
for (; i < l; ++i) {
tr = document.createElement('tr'); //new row
tbod.appendChild(tr);
rowdata = data[i].split("|", 6); //separate bits
for (ii = 0, ll = rowdata.length; ii < ll; ++ii) {
td = document.createElement('td'); //new cell
td.appendChild(document.createTextNode(rowdata[ii]));
tr.appendChild(td);
}
}
}
}
}
</script>
It works fine and the output looks like this.
colh01 colh02 colh03 colh04 colh05
data11 data12 data13 data14 data15
data21 data22 data23 data24 data25
data31 data32 data33 data34 data35
data41 data42 data43 data44 data45
Then I wanted to insert a column (colh6) that will have data taken from first column. It should look like this
colh01 colh02 colh03 colh04 colh05 colh6 (new column)-->(link to file)
data11 data12 data13 data14 data15 'file-<data11>.pdf' -->(href='http://locahost/file-<data11>.pdf')
data21 data22 data23 data24 data25 'file-<data21>.pdf' -->(href='http://locahost/file-<data21>.pdf')
data31 data32 data33 data34 data35 'file-<data31>.pdf' -->(href='http://locahost/file-<data31>.pdf')
data41 data42 data43 data44 data45 'file-<data41>.pdf' -->(href='http://locahost/file-<data41>.pdf')
How do I go about this? The data is a hyperlink that user can click to open the file.
You’ve completed the hard part, all you’re missing is how to create a link using Javascript. If you just add these lines after your loop, it will create a link using the content of the first column;
More info on creating dynamic links here.