Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display links from XML into HTML

Status
Not open for further replies.

guntersammet

Programmer
Jun 8, 2001
2
CA
Howdy,
I defined an XML document:

Code:
...
<LIST>
  <COMPANY_REC ID=&quot;1&quot;>
    <COMPANY>My Company</COMPANY>
    <WEB>[URL unfurl="true"]www.sammet.net</WEB>[/URL]
    <EMAIL>Me@MyCompany.com</EMAIL>
    <CONTACT>MyContact</CONTACT>
  </COMPANY_REC>
</LIST>
...

and tried to display it in HTML:

Code:
<table datasrc=&quot;#xmldso_list&quot; border=&quot;1&quot;>
<thead>
<tr align=&quot;left&quot;><th>Company name</th><th>Web</th><th>Email</th><th>Contact</th></tr>
</thead>
<tr align=&quot;left&quot;>
<td onclick=&quot;testclick(this)&quot;><div datafld=&quot;COMPANY&quot;></td>
<td onclick=&quot;testclick(this)&quot;><div datafld=&quot;WEB&quot;></td>
<td onclick=&quot;testclick(this)&quot;><div datafld=&quot;EMAIL&quot;></td>
<td onclick=&quot;testclick(this)&quot;><div datafld=&quot;CONTACT&quot;></td>
</tr>
</table>

I was able to display the links (web and email) but I couldn't get them to work as link.
How can I get the webpage to display the links that when I click on them, that they go to the link. Can I define the target as well?
TIA Gunter
 
You should still need the basic <A HREF=&quot;url&quot;></A> link tag in there somewhere. Also, you are calling a function &quot;testclick()&quot; that is not defined in the code you provided. If you used the HTML link tag in the definition of that function, that is the first place I would look. You may want to post that script as well to see if the problem lies in there.
 
This is the contents of the function:

Code:
<script language=&quot;JavaScript&quot;>
function testclick(field)
{
var row=field.parentElement.rowIndex
xmldso_list.recordset.absoluteposition=row
td_name.innerHTML=xmldso_list.recordset(&quot;COMPANY&quot;)
td_web.innerHTML=xmldso_list.recordset(&quot;WEB&quot;)
td_email.innerHTML=xmldso_list.recordset(&quot;EMAIL&quot;)
td_contact.innerHTML=xmldso_list.recordset(&quot;CONTACT&quot;)
}
</script>

I tried to play around with the &quot;a-tag&quot;. In order to make the link work, I have to place the url in <A HREF=&quot;...place url here...&quot;></A>.
The table is automatically produced by the div tag (...<td onclick=&quot;testclick(this)&quot;><div datafld=&quot;WEB&quot;></td>...) and I couldn't find a way to insert an &quot;a-tag&quot; there.
Hope this helps!
Gunter
 
I'm not a JavaScript expert, but I don't see where you have actually defined an action in that script. You need some type of command to generate the action. If, for instance, you wanted to open the link in a new window you would use:

window.open(&quot;yoururl&quot; &quot;windowname&quot; &quot;window attributes&quot;)

The problem is not with your XML, it is in your JavaScript. I am sure that if you just look through old headers in the JavaScript forum you will find a script right away that fits your needs.
 
*:->* Thanks! Getting closer to the get it working the way I want it to work. Here the code I used:

Code:
<script language=&quot;JavaScript&quot;>
function testopen(field)
{
var row=field.parentElement.rowIndex
xmldso_list.recordset.absoluteposition=row
window.open(xmldso_list.recordset(&quot;WEB&quot;), &quot;NEW&quot;)
}
</script>

...
Implementation:
<td onclick=&quot;testclick(this); testopen(this)&quot;><div datafld=&quot;WEB&quot;></td>

THANKS AGAIN *:->*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top