October 2nd, 2006, 01:31 AM
Function not returning newest variable
Here's the deal: I want my doAjaxRequest function to open a CFM file, which then calls a function in a CFC file depending on the ?functions= url. Well, everything works perfectly, except result. The particular thing I'm doing is when a user is typing in a desired username, onkeyup calls this function which then makes a database query to see if the username is already taken. The thing is, inside the onreadystatechange function, result is updated as intended, but when i get out of that, and return result, it's always one result behind.
For example, they type in "test", but "test" is taken. But, instead of it returning false when they type the second "t", it says true. But if I backspace or type another letter, it will say false. The same is for the very first keystroke, except instead of saying true, it will return undefined(null, i suppose).
function doAjaxRequest(type, functions, location)
aXmlHttp.open(type, "/ajax/ajax.cfm?"+functions, true);
if (aXmlHttp.readyState == 4)
var a = aXmlHttp.responseText;
if(location != null)
document.getElementById(location).innerHTML = a;
result = a;
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.