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

create a link programatically? 2

Status
Not open for further replies.

simon551

IS-IT--Management
May 4, 2005
249
I'd like to do something like this:

document.getElementById("fxlbl").innerHTML = "Exchange Rate:<a href="#">toggle fxRate</a>";

basically I want the script to update a field with a description and a link. I have the first part working

Code:
document.getElementById("fxlbl").innerHTML = "Exchange Rate:"

, just need to make a link.
 
Hi

Just quote correctly :
Code:
document.getElementById("fxlbl").innerHTML = [red]'[/red]Exchange Rate:<a href="#">toggle fxRate</a>[red]'[/red];

[gray]// or[/gray]

document.getElementById("fxlbl").innerHTML = "Exchange Rate:<a href=[red]\"[/red]#[red]\"[/red]>toggle fxRate</a>";

Feherke.
 
The first thing you put should work as well, just make sure to escape your quotes:
Code:
document.getElementById("fxlbl").innerHTML = "Exchange Rate:<a href=[!]\"[/!]#[!]\"[/!]>toggle fxRate</a>"

Additionally, you could create the element using DOM methods and append it after you have set the innerHTML. Something like this:
Code:
document.getElementById("fxlbl").innerHTML = "Exchange Rate:";
var newLink = document.createElement("a");
newLink.setAttribute("href", "#");
newLink.innerHTML = "toggle fxRate";
newLink.onclick = function () {
   //build the onclick function here
};
document.getElementById("fxlbl").appendChild(newLink);

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top