W
Wayne Wengert
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?
Wayne
================= code ==============
<script language="Javascript">
<!--
var req;
var response;
var city;
var state;
function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}
function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}
//-->
</script>
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?
Wayne
================= code ==============
<script language="Javascript">
<!--
var req;
var response;
var city;
var state;
function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}
function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}
//-->
</script>