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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build an "a href" inside a "td" tag programmatically

Status
Not open for further replies.

vvcarpio

Technical User
Apr 25, 2003
4
US
Hi.

I'd like to build an "a href" tag inside a table "td" tag programmatically. Basically something like the following:

<table>
<tr>
<td>
<a href="javascript:void(0);" onclick="vbscript:viewAttachment 123" title="View document">View document</a>
</td>
</tr>
</table>


When I run my code below, however, and click on the generated link, nothing happens. It's like the subroutine "viewAttachment" isn't being called at all. Am I doing something wrong. Thanks!

set objTBody = document.createElement("tbody")
set objTR = document.createElement("tr")
set objTD = document.createElement("td")

set objA = document.createElement("a")

set objAttribute = document.createAttribute("href")
objAttribute.nodeValue = "javascript:void(0);"
objA.setAttributeNode obJAttribute
set objAttribute = nothing

set objAttribute = document.createAttribute("onclick")
objAttribute.nodeValue = "vbscript:viewAttachment " & intDocID
objA.setAttributeNode obJAttribute
set objAttribute = nothing

set objAttribute = document.createAttribute("title")
objAttribute.nodeValue = "View document"
objA.setAttributeNode obJAttribute
set objAttribute = nothing

objA.appendChild document.createTextNode("View document")
objTD.appendChild objA
objTR.appendChild objTD
objTBody.appendChild objTR
 
Sorry...it's working now. I must have had a silly typo in my code. My apologies. Thank you.
 
Oops again. It's still not working. Any help appreciated.
 
I got it to work. I basically rewrote the vbscript to javascript and changed:

set objAttribute = document.createAttribute("onclick")
objAttribute.nodeValue = "vbscript:viewAttachment " & intDocID
objA.setAttributeNode obJAttribute
set objAttribute = nothing

to:

objA.onclick = function(){viewAttachment(intDocID)};

Thank you. (It turns out IE doesn't handle "setAttribute onclick" like other attributes.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top