Jump to content

[RESOLVED]To change link dynamically using innerHTML


Jangrina

Recommended Posts

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 by Jangrina
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...