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).

Well, first off there is an AJAX forum. I will have a moderator move it there.

Quote:

Originally Posted by Psytherium

it's always one result behind.

Sounds to me like you are experiencing something similar to JavaScripts onkeypress vs. onkeyup.

Is this the same thing you are battling?

Code:

This is one behind when typing.
<input type="text" onkeypress="alert(this.value)">
This is on time.
<input type="text" onkeyup="alert(this.value)">

October 2nd, 2006, 10:54 AM

Psytherium

Re: Function not returning newest variable

EDIT: Well, I took a glance at the AJAX forum and saw a thread that talked about SJAX(SynchronousJAX), so I gave it a try and it works. Trying to learn client-side coding, server-side coding, and conventions like AJAX all at the same time is pretty difficult, ahhh.