I am writing an AJAX postcode look up script and I am having problems with the responseXML part.
I can get the responseXML and it shows the response using an alert() but when I try to get specific node values I get errors specifically SCRIPT438: Object doesn’t support property or method ‘getElementByTagName’.
<script type="text/javascript">
var xmlhttp;
function doLookup() {
var postcodetosearch = document.getElementById("ctl00_pageContent_txtPostalCode").value;
var mydiv = document.getElementById("ctl00_pageContent_postCodeLookupContainer");
mydiv.style.display = "inline";
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var response = xmlhttp.responseXML;
var myresponse1;
myresponse1 = response.xml
myresponse1 = "<p>" + response.getElementByTagName("street")[0].firstChild.nodeValue;
document.getElementById("postcoderesult").innerHTML = myresponse1;
}
}
xmlhttp.open("GET", "http://geo.jamiethompson.co.uk/" + postcodetosearch + ".xml",false);
xmlhttp.send(null);
}
</script>
Can someone guide me?
There is no such method as
getElementByTagName(with the word “Element” as singular). It’sgetElementsByTagName(with the word “Elements” as plural; docs).