I tried your code John, but it dont seem to work well.
Here is my code snippet:
Code:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","cd_catalog.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
var y=x[0].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue;
alert(y);
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
document.write('<a href="#" onclick="window.location = ' + y + '; return false;">Test</a>');
</script>
</body>
</html>
I am basically trying to read the contents of an xml file and storing it in variable y. and using that as an href.
When in a lone a href tag, it works fine and www.google.com opens up just fine, as the value of y is www.google.com, but the same fails in document.write.
Bookmarks