PDA

View Full Version : How to dynamically assign <a href> value to <td> data in a loop?? Somebody pls help!!



SRD
04-19-2010, 12:09 PM
Hi,

I have an issue in dynamically assigning Onclick/<a href> action to the data within <td> cell.
Am pulling out data from a XML file, and displaying it as a table data on HTML page within a for loop. But within a loop, when am trying to do <a href> for the data by providing a dynamically changing URL value, the data is not getting displayed.

I donot know how to do it!! Can anyone help me out?

Following is the code that am using,

for (var i=0;i<x.length/6;i++)
{
document.write("<tr>");
while(k<6)
{
document.write("<td>");
document.write("<a href=x[j].getElementsByTagName("name")[0].childNodes[0].nodeValue"'+.html+'"">");
document.write(x[j].getElementsByTagName("name")[0].childNodes[0].nodeValue);
document.write("</a>");
document.write("</td>");
j++;
k++;
}
k=0;
document.write("</tr>");
}


In the code, name is the data element that am pulling from XML file.
On clicking each name, an URL should appear which has name as part of it.
For example, if the name is Kiran, then the URL will be 'Kiran.html'.

Is it possible to do it this way? Please suggest if there is any other way?

Horacio
05-08-2010, 01:46 PM
while(k<6)

what's the initial value for k?
I think you should have :
k=0;
while(k<6)
...