The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Javascript/AJAX function calls

Full disclosure: I am crap at Javascript, but have still managed to promise someone in the office a "fancy on-the-fly updating boxes" (his words, not mine). That would be an AJAX thing then, fetching data from the db as you type.

I found a working example on the web and managed to get it working for one textbox in the form, but when I wanted to make it more dynamic and send the element name as a parameter to the function instead of hard-coding it, I run into trouble. I know what the problem is (I can't pass the function with a parameter to the OnReadyStateChange method, but I'll be damned if i know how to get it working. Any help appreciated. Thanks!

The onreadystatechange is for the data coming back from the server. Anything you are passing to the server needs to either go in the querystring on the URL when you are using GET or can be passed using POST. Either way it needs to be set before calling send and cannot be set when the server replies that it is ready to provide the answer.

Yeah, but the OnReadyStageChange gets something from the handleSearchSuggest function, which I am trying to pass a parameter to. IE complains about "Not implemented" if I pass a parameter. If I do searchReq.onreadystatechange = handleSearchSuggest, that works fine.

You are using the request as a single instance for all controls/elements. If you continue with this method, you can simply define a global var which will be updated just before you call the ajax method.

Ideally though, you should really create a new instance of the ajax request for each element.