Hi!
Im doing an app where i get some data from a mssql db
That data is used to fill some <selects> so the data is taken from an asp script that returns a string with the data.
The scripts returns de data correctly.
That string is saved in a javascript variable for splitting it and with the resulting array, fill the options in the selects.
The problem occurs i think in my XMLHTTPRequest code
The onchange of the first <select> triggers the request for the data, but the first response is not what i expected.
But when i trigger again the request, the response from the server is the one i expected in the first time i triggered the request.
If i trigger the request again, the data that the server returns is the one i needed in the event just before.
And this gets happening.
Here is my code:
this function is called on the onchange event of my select
[CODE]
var respuesta=””;
function switch_Select(sorigen,sdestino,param,tabla)
{
var i;
i=0;
var lorigen = sorigen.options[sorigen.selectedIndex].value;
var ldestino = document.getElementById(“s”+sdestino);
if(sdestino==”request”)
sdestino=”fullname”;
if(sdestino==”respons”)
sdestino=”name”;
origenajax(lorigen,sdestino,param,tabla);
ldestino.options.length=0;
ldestino.options[0]=new Option(“–Seleccione–“,0);
var arreglo=respuesta.split(“:”);
var arrlength= arreglo.length;
for(i=1;i<arrlength;i++)
ldestino.options[i]=new Option(arreglo[i],arreglo[i]);
}
This is my XMLHTTPRequest code.
[CODE]
function origenajax(id,col,param,tabla)
{
XMLHttp=null;
try
{
XMLHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch(e)
{
try
{
XMLHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch(e)
{
XMLHttp=new XMLHttpRequest();
}
}
var url=”sel.asp”;
url+=”?id=”+String(id)+”&t=”+col+”&p=”+param+”&ta=”+tabla+”&sid=”+Math.random();
XMLHttp.onreadystatechange=stateChanged;
XMLHttp.open(“GET”,url,true);
XMLHttp.send(null);
}
function stateChanged()
{
if(XMLHttp.readyState==4||XMLHttp.readyState==”complete”)
respuesta=XMLHttp.responseText;
}
Thanks