By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

Insert Hyperlink from XML

P: 1

I'm a newbie to web design, and have been piecing togther 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 experince 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></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:

Expand|Select|Wrap|Line Numbers
  1. var webaddress = xmldoc.getElementsByTagName('webaddress').item(1);
  2. txt3 = document.createTextNode(webaddress);
  3. document.getElementById('webaddressdiv').appendChild(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 ?
Aug 6 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 2,057
Expand|Select|Wrap|Line Numbers
  1. var webaddress = xmldoc.getElementsByTagName('webaddress').item(1);  
  2. txt3 = document.createTextNode(webaddress);
  3. document.getElementById('webaddressdiv').appendChild(txt3);
Can you surround it in an anchor <a> tag?
eg like: <a href=""></a>
Expand|Select|Wrap|Line Numbers
  1. anchor = document.createElement("a");
  2. href = document.createAttribute("href");
  3. href.nodeValue = webaddress;
  4. anchor.appendChild(href);
  5. anchor.appendChild(txt3);
  6. document.getElementById('webaddressdiv').appendChild(anchor);
Aug 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.