vn412 0 Light Poster

Hi,

Im using the following script

var ajax1 = new Ajax_init();
		ajax1.GetData('bindddl,ddlCity_01,SELECT cityid,cityname FROM city where countryid='+text.value+' order by cityname','ddlCity_01');
		
		
		
		var ajax2 = new Ajax_init();
		var ctyid;
		
		if(document.getElementById('ddlCity_01').value){
			ctyid=document.getElementById('ddlCity_01').value;}
			else{
			alert('szdfzxf');
			 ctyid=0;
			}
		
		ajax2.GetData('idols, where cityid='+document.getElementById('ddlCity_01').value+ ' and countryid='+document.getElementById('ddlCountry_01').value ,'divlist',p);
	}

Here is the ajax code:
function Ajax_init() {
this.GetData= function (val,id,p,load)
{
var ctrl=null;
var d=new Date();
var timestamp=d.getMinutes()+'_'+d.getSeconds()+'_'+d.getMilliseconds();
var xmlHttp=GetXmlHttpObject()// don't make it global as it will create prob when making multiple calls

if(p==null)
p=1;
if(load==null)
load=1;


if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}
ctrl=document.getElementById(id);
if(load==1)
ctrl.innerHTML="<img src='images/loading.gif' />";
xmlHttp.onreadystatechange=function() { HandleGetData(id,xmlHttp); }
xmlHttp.open("GET", 'AjaxPage.php?q='+val+'&page='+p+'&order='+document.getElementById('hdnorder').value+'&timestamp='+timestamp, true)
xmlHttp.send(null);
}
}

function HandleGetData(div,xmlHttp)
{
//alert(div);
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById(div).innerHTML=xmlHttp.responseText
LoadWindow();
}

}

The problem is I m getting the correcr ctyid when i give alert (above in else condition), but if i do not give it when i change country the i get old ctyid or ctyid= undefined

Please help.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.