<script language="javascript">
var theURL = "/examples/servlet/MyGoogleSearchServlet?search=";
var http = getHTTPObject(); 

function handleHttpResponse() {
  if (http.readyState == 4) {
    GoogleSearchResults.innerHTML = http.responseText;
  }
}

function updateGoogleResults(formElement) {
  var searchQuery = document.forms[0].elements[formElement].value;
  http.open("GET", theURL + escape(searchQuery), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function getHTTPObject() {
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
     try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
        xmlhttp = false;
     }
  }

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }

  return xmlhttp;
}
</script>