"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:be********************@comcast.com...
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>
I don't know about ASP.NET but this works for me:
<html>
<head>
<title>xml_zip.htm</title>
<script type="text/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 + ", " + state);
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() {
loadXMLDoc('http://www.wengert.org/zipcodes.asmx/GetZip?z=' +
document.forms[0].txtZIP.value);
}
</script>
</head>
<body>
<form>
<input type="text" name="txtZIP" size="5" maxlength="5" value="">
<input type="button" value="Lookup" onclick="loadxml()">
<br>City, State :
<input type="text" name="txtcity">
<input type="text" name="txtstate">
<br>
<textarea name="output" cols="100" rows="30"></textarea>
</form>
</body>
</html>
I changed your
function loadxml(form) {
to
function loadxml() {
as well as the indentation for (my) readability.