Click to See Complete Forum and Search --> : variable href
Simple question but I've managed to stump myself (pretty easy to do...) ;)
How would I write a variable called from a javascript file into the href of a link tag I've tried href=''+variable+'' (those are all single quotes), and variations on that theme, but no joy...
IxxI
If you're doing this after the page has loaded, use document.getElementByTagName("tagName")[n].href (where tagName is the element, for example, an anchor [<a>] element, and n is the number in the array of elements in the page).
Jona
Khalid Ali
06-02-2003, 10:12 AM
Without going into your need to do it this way..
here is how you can do that
<a href="#" onclick="this.href=url;">W3c</a>
where url is a global variable
url = "http://w3c.org"
How about:
document.write('<a href="'+variable+'">your variable link</a>');
You can also use the document.links[] or document.anchors[] arrays, and change the href:
var url = "http://www.W3C.org/";
document.links[0].href = url;
Jona