Forum Moderators: open
I've been fooling around with xmlhttprequest, I've had problems with readyState for a while.
I have a function to process the requests, something like:
function processReq(){
if(http.readyState == 4){
// do stuff
}
}
Here's the quandary:
If I call the function like this:
http.onreadystatechange = processReq();
Nothing is returned, the readyState just seems to stay at 1.
But, if I do this:
http.onreadystatechange = processReq;
everything is just fine and dandy.
So, what's the difference between processReq() and processReq?
Thanks!
-Sned
Is there anyway to use javascript to select a certain number of letters a textbox?
Say for instance, the textbox contains "elephant", I want the script to only select "phant".
I'm trying to work on an autocomplete thing, selecting people from a database based on what a user types in the text box.
Thanks!
-sned
<edit>
I found these methods in Google's suggest javascript:
createTextRange
setSelectionRange
I think those will do the trick!
</edit>
[edited by: sned at 7:45 pm (utc) on June 20, 2005]
But, if I do this:
http.onreadystatechange = processReq;
everything is just fine and dandy.
I could be wrong but i think it's because processReq is being called as a variable, which is being assigned to http.onreadystatechange, whereas when you use processReq(), it assigns http.onreadystatechange the value of the function, which is generally nothing, hence (I assume) the breakage.
Then again I could be totally off, but there are plenty of JavaScript gurus about to help out :-)
J.