// If the user is using Mozilla/Firefox/Safari/etc
if (window.XMLHttpRequest) {
//Intiate the object
xmlhttp = new XMLHttpRequest();
//Set the mime type
xmlhttp.overrideMimeType('text/xml');
} else if (window.ActiveXObject) {
//Intiate the object
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function preSearch() {
//Put the form data into a variable
var theQuery = document.getElementById('query').value;
var theQuery_a = document.getElementById('query2').value;
var theQuery_b = document.getElementById('query3').value;
//If the form data is *not* blank, query the DB and return the results
if(theQuery!== "") {
//Change the content of the "result" DIV to "Searching..."
//This gives our user confidence that the script is working if it takes a moment for the result to be returned. However the user will likely never see this...
document.getElementById('result').innerHTML = "Searching...";
//This sets a variable with the URL (and query strings) to our PHP script
var url = 'test.php?type=' + theQuery + '&Keyword=' + theQuery_a + '&church=' + theQuery_b;
//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method
xmlhttp.open('GET', url, true);
//Check that the PHP script has finished sending us the result
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//Replace the content of the "result" DIV with the result returned by the PHP script
document.getElementById('result').innerHTML = xmlhttp.responseText + ' ';
} else {
//If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
document.getElementById('result').innerHTML = 'Error: preSearch Failed!';
}
};
xmlhttp.send(null);
}
}
//-->
Edited by arandlett, 16 May 2006 - 11:34 AM.
