Well, I played with that zip code tutorial, (
http://www.webpasties.com/xmlHttpRequest/) and changed the output to write to <span> elements instead of <input> elements.
These two links I found to be invaluable:
http://www.mozilla.org/docs/dom/domref/dom_shortTOC.html
http://www.devguru.com/Technologies/xmldom/quickref/xmldom_index.html
Apple Developer has a nice discussion also, involving the iTunes RSS feed:
http://developer.apple.com/internet/webcontent/xmlhttpreq.html
Another interesting link:
http://jibbering.com/2002/4/httprequest.html
I installed the Developer Tools extension to Firefox; its DOM inspector is great, and the JavaScript console helps me figure out where my typos are...
The zip code thing isn't really very interesting in itself, but how the javascript works out is interesting, so I'll just post the relevant parts of the HTML file:
...
<script type="text/javascript">
var url = "getCityState.php?param="; // The server-side script to be called
// What to do with the returned data, this I understand
function handleHttpResponse() {
if(http.readyState == 4) { // If the http object has done its thing
// Split the comma-delimited response into an array
results = http.responseText.split(",");
var cityText = document.createTextNode(results[0]);
var stateText = document.createTextNode(results[1]);
var cityRef = document.getElementById("city"); // The first span
cityRef.replaceChild(cityText,cityRef.lastChild);
var stateRef = document.getElementById('state'); // The second span
stateRef.replaceChild(stateText,stateRef.lastChild);
}
}
// Call the server-side script - need to study the open and send functions
function updateCityState() {
var zipValue = document.getElementById('zip').value; // From the form
http.open("GET", url + escape(zipValue), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
// Cross-browser goodness, not sure I want to understand it...
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
// this part is clear enough
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
// We create the HTTP Object that gets used in the function updateCityState()
var http = getHTTPObject();
</script>
...
<form action="post">
<p>
ZIP code:
<input type="text" size="5" name="zip" id="zip" onblur="updateCityState();" />
</p>
</form>
City: <span name="city" id="city"> </span><br />
State: <span name="state" id="state"> </span>
...