// Set path to PHP script var phpscript ='/blog/wp-content/themes/StopForeclosure/ajax.php' /* ============================ MAKE XMLHttpRequest OBJECT ============================ */ createRequestObject=function() { var req; if(window.XMLHttpRequest){ // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if(window.ActiveXObject){ // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else{ // There is an error creating the object, // just as an old browser is being used. alert('There was a problem creating the XMLHttpRequest object'); } return req; } // Make the XMLHttpRequest object var http = createRequestObject(); /* ============================ GET COUNTIES ============================ */ getCountiesRequest=function(statesRef) { //get state value var state=statesRef.options[statesRef.options.selectedIndex].title; // Open PHP script for requests //http.open('get', phpscript, true); var params = 'state='+state+'&task=getCounties&time='+Date(); http.open('post', phpscript, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); http.onreadystatechange = getCountiesResponse; http.send(params); }//end function getCountiesRequest getCountiesResponse=function() { if(http.readyState == 4 && http.status == 200){ // Text returned from PHP script var response = http.responseText; if(response) { //add clients list var selectRef=document.getElementById('county_list'); var optionsArray=eval('('+response+')'); //deselect county list if no results if(optionsArray.length==1){ selectRef.disabled=true; return; } else{ selectRef.disabled=false; } //remove previous option list while(selectRef.firstChild){ selectRef.removeChild(selectRef.firstChild); } for(var i=0;i < optionsArray.length;i++){ var optionRef=document.createElement('option'); optionRef.title=optionsArray[i]['value']; optionRef.value=optionsArray[i]['value']; optionRef.appendChild(document.createTextNode(optionsArray[i]['text'])); selectRef.appendChild(optionRef); } }//end if response }//end if finish }//end function getCountiesResponse /* ============================ GET EMAIL_ADDRESS ============================ */ getEmailRequest=function() { //get county value var countyRef=document.getElementById('county_list'); var county=countyRef.options[countyRef.options.selectedIndex].title; var statesRef=document.getElementById('state_list'); var state=statesRef.options[statesRef.options.selectedIndex].title; // Open PHP script for requests //http.open('get', phpscript, true); var params = 'county='+county+'&state='+state+'&task=getEmail&time='+Date(); //alert(params); http.open('post', phpscript, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); http.onreadystatechange = getEmailResponse; http.send(params); }//end function getEmailRequest getEmailResponse=function() { if(http.readyState == 4 && http.status == 200){ // Text returned from PHP script var response = http.responseText; if(response) { document.getElementById('email_address').value=response; }//end if response }//end if finish }//end function getEmailResponse