Jump to content

Insert Hyperlink from XML


oconndav

Recommended Posts

Hi,I'm a newbie to web design, and have been piecing together a site for a friend over the last few weeks basically by Googling everything I don't understand and trying to fit it all together. It's been an uplifting experience and have picked up some knowledge of MySQL, PHP, XML and AJAX along the way.I nearly have all of the functionality I need to move forward but there is one thing really annoying me because I can't fix it, and I have had much look searching through usual resources..Basically, I am dynamically displaying data on my HTML page by reading values from an XML file and writing to HTML using create.textnode().Everything is working fine except that one of the fields I want to display is a web address and I want this text field to display as a hyperlink on the webpage. So if the XML entry was <webaddress>http://www.hotmail.com</webaddress> I need that to display as a hyperlink to Hotmail on the page. Currently it just gets inserted as a text string.Example of the code I am using is:

      var webaddress = xmldoc.getElementsByTagName('webaddress').item(1);      txt3 = document.createTextNode(webaddress);     document.getElementById('webaddressdiv').appendChi  ld(txt3);

So in the above code I am reading the text value from the XML file, create a text node containing the text string of the webaddress and then writing it to a tag called webaddressdiv.Any ideas as to how I make this dynamic text string into a dynamic hyperlink ?

Link to comment
Share on other sites

You can use a combination of the HTML DOM and the XML DOM to do this:

var webaddress = xmldoc.getElementsByTagName('webaddress').item(1);var link = document.createElement("a");link.innerHTML = webaddress;link.href = webaddress;document.getElementById("webaddressdiv").appendChild(link);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...