var xmlHttp=null;
function fetchData(url,targetElem) {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Your browser does not support AJAX!");
return false;
} else {
//alert ("got in fetchdata!");
}
email_summary = document.getElementById("email_summary").value;
record_id = document.getElementById("record_id").value;
//add random number to avoid cached data
if( -1==url.indexOf("?") )
url += "?email_summary="+email_summary+"&record_id="+record_id+"&sid="+Math.random();
else
url=url+"email_summary="+email_summary+"&record_id="+record_id+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){stateChanged(targetElem);};
xmlHttp.open("GET",url,true);
xmlHttp.send('');
}
function stateChanged(containerElem) {
if (xmlHttp.readyState==4) {
//alert ("got in statechanged!"+containerElem);
switch(containerElem) {
case "to-set-focus-upon-returning":
// ************ make sure to add div id="whatever" to ***************
var data = null;
eval("data =" + xmlHttp.responseText + ";");
//at this point data is an array of objects, so you need to iterate through it
for( var i=0; i < data.length; ++i) {
document.getElementById(data[i].targetDiv).innerHTML = data[i].html;
//alert(data[i].targetDiv)
}
if ( document.getElementById('countryname').value !='' ) {
setTimeout("document.getElementById('civicnumber').focus()",500)
} else {
setTimeout("document.getElementById('country').focus()",500)
}
break;
default:
var data = null;
eval("data =" + xmlHttp.responseText + ";");
for( var i=0; i < data.length; ++i) {
document.getElementById(data[i].targetDiv).innerHTML = data[i].html;
}
break;
}
xmlHttp=null;
}
}
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
|
|