Jangrina Posted March 4, 2013 Share Posted March 4, 2013 (edited) Hi, Below is my code.I am stuck in line shows below. function createRows() //to create rows using innerHTML{ var tbody = document.getElementById("CONTENT"); //tbody = your table body tbody.innerHTML = ""; //empty table body for (i=1; i<=73; i++) { tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = referenceNo(i); //ref. no td = tr.insertCell(-1); td.innerHTML = trackNo(i); //track td= tr.insertCell(-1); td.innerHTML = ; //I am stuck here }} I would like to have function call there where it will receive a value to link it to pdf file and also display the title. In HTML, I would be writing it like below. But, I want it to be dynamically set according to the value of i. <a href="3-Management & Marketing\103.pdf" target="_blank">XXXX</a> How to do this? Pls help. Edited March 6, 2013 by Jangrina Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2013 Share Posted March 4, 2013 Where does the filename come from? You can have a function return that markup, but it needs to get the filename from somewhere. Link to comment Share on other sites More sharing options...
Jangrina Posted March 4, 2013 Author Share Posted March 4, 2013 The file is set according to the value of i. It is something like this. if i ==1 then href = "3-Management & Marketing\101.pdf"else if i == 2 then href = "1-Business\103.pdf" Link to comment Share on other sites More sharing options...
Jangrina Posted March 4, 2013 Author Share Posted March 4, 2013 Pls look into the code below.When run on browser, it cannot find the path.What is wrong? function createRows() //to create rows using innerHTML{ var tbody = document.getElementById("CONTENT"); //tbody = your table body tbody.innerHTML = ""; //empty table body for (i=1; i<=73; i++) { tr = tbody.insertRow(-1); //append a row in table body td = tr.insertCell(-1); td.innerHTML = referenceNo(i); //ref. no td = tr.insertCell(-1); td.innerHTML = trackNo(i); //track td = tr.insertCell(-1); td.innerHTML = getTitle(i); }}/** ----------------------------------------- TO RETURN TITLE -------------------------------------------------*/function getTitle(i){ var title = ""; switch(i) { case 1: title = "<a href=\"3-Management & Marketing\103.pdf\" target=\"_blank\">XXXXX</a>"; break; } return title;} Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2013 Share Posted March 4, 2013 It sounds like you just need to define another function like the other 2 for referenceNo and trackNo, and have that function build and return the HTML string with the filename in it. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2013 Share Posted March 4, 2013 The above code will work if the value of i is 1, it will return that string. You should probably use / to separate the path instead of \ though. Link to comment Share on other sites More sharing options...
Jangrina Posted March 6, 2013 Author Share Posted March 6, 2013 Thank you.It works. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now