Forum Moderators: open
<form name='input_form' onsubmit="return txtSelected();">
<input type="text" id="searchTXT" name="searchTXT" size = "60"
value = "Enter test name or CPT code"
onFocus="this.value==this.defaultValue?this.value='':null "/>
<input type='submit' id='txt_submit' name='txt_submit' value='search'/>
</form>
<script>
function txtSelected() {
var txtValue = document.getElementById('searchTXT').value;
ajaxFunction(txtValue);
return false;
}
function ajaxFunction(txtValue) {
var ajaxRequest; // The variable that makes Ajax possible!
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
ajaxRequest = new XMLHttpRequest();
} else { // code for IE6, IE5
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function () {
if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
alert("request finished and response is ready. ready state 4");
// *** URL is global
URL = ajaxRequest.responseText;
location.href = URL;
} else if (ajaxRequest.readyState == 3) {
alert("processing request Request is waiting for user interaction ");
} else if (ajaxRequest.readyState == 2) {
alert("request received Request is fully loaded");
} else if (ajaxRequest.readyState == 1) {
alert("server connection established Request is loading ");
} else if (ajaxRequest.readyState == 0) {
alert("Object is uninitialized or request not initialized ");
}
}
var queryString = "?t=" + Math.random() + "&userInput=" + txtValue;
ajaxRequest.open("GET", "serverResponse.php" + queryString, true);
ajaxRequest.send(null);
}
</script>