Subscribefunction loadXMLDoc(keywords) {
// replace spaces with + sign
keywords.replace(" ","+");
url = "http://------.----.org/peoplefinder/?cmd=keyword-search&keyword="+keywords;
req = new XMLHttpRequest();
req.open("GET", url, false);
req.send(null);
req.onreadystatechange = buildTbody();
content = req.responseText;
}
function buildTbody() {
// initialize vars used throughout function
var tbody, tr, td, txt;
// prepare existing tbody element
tbody = document.getElementById("myTbody");
clearTBody(tbody);
// temporary container while accumulating rows
var docFrag = document.createDocumentFragment();
// wait for results to finish coming in from server
if (req.readyState == 4) {
if (req.status == 200) {
// isolate contents of eighth table,
// which contains the search results
var resultTable = content.getElementsByTagName("table")[3];
// put table rows into resultRows
var resultRows = resultTable.getElementsByTagName("TR");
// loop through resultRows array
// (skipping first/header row)
// and assemble rows for new tbody
for (var i = 1; i < resultrows.length; i++) {br>
// put the cells from the current row into the resultCells array
var resultCells = resultRows[i].getElementsByTagName("TD").innerHTML;
tr = document.createElement("tr");
// loop through resultCells array to assemble
// cells for new row
for (var j = 0; j < 5; j++) {br>
td = document.createElement("td");
txt = document.createTextNode(resultCells[j]);
td.appendChild(txt);
tr.appendChild(td);
}
docfrag.appendChild(tr);
}
} else {
tr = document.createElement("tr");
tr.style.backgroundColor = "rgb(100%, 10%, 0%)";
tr.style.color = "#ffffcc";
td = document.createElement("td");
td.style.textAlign = "center";
td.colSpan = "4";
txt = document.createTextNode("Error retrieving data");
td.appendChild(txt);
tr.appendChild(td);
docFrag.appendChild(tr);
}
tbody.appendChild(docFrag);
}
}
function clearTBody(tbody) {
while (tbody.childNodes.length > 0) {
tbody.removeChild(tbody.childNodes[0]);
}
}
>>You are not logged in, either login or create an account to post comments
posted by jpburns at 5:17 AM on August 3, 2005