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.

Ajax.Autocompleter from script.aculo.us questions

I have a couple places in my PHP app where I would love to replace long drop down menus with a text field that has some autocomplete help. I have tried it out and it works great, but I have two problems.

First, is including the scriptaculous.js supposed to auto include the other files? I couldn't get my demo to work until I included the controls and effects files as well.

Second, this is the down side of the text field vs the drop down I think. Let's say I want to pull up a list of users in the system. Now because the users are actually identified by a unique ID field instead of the string of First Name, Last Name the drop down was easy to set the value to the integer ID while the drop down read a nice string name.

Is there some way for the text field in auto complete to show a string to the user, yet submit a different value tied to it (such as a int ID identifier) in the POST to the next page?

Thanks for the ideas/help.

mitechie.com
"Techies just think a little differently
...at least that is what they keep telling me."

In regard to your problem, you could always have a hidden input field which contains the id, so with the autocomplete call, pass the index key to a javascript function which stores it in a hidden input field, then put the full name in the pretty box which the user sees?

So you simply use return to send the data back to the autocompleter like you would in a regular function? I thought you would just echo the data onto the page and the autocompleter would read it off the page.

So you simply use return to send the data back to the autocompleter like you would in a regular function? I thought you would just echo the data onto the page and the autocompleter would read it off the page.

Sorry, I didn't mean literally use the return command. Yes, you merely output the results you would like to get back to the page.

Weird, I am using the following code on my server page just to test it out, but it doesn't seem to do anything. It should just display the printed values as soon as the number of characters in the input field is more than 2 right?

Weird, I am using the following code on my server page just to test it out, but it doesn't seem to do anything. It should just display the printed values as soon as the number of characters in the input field is more than 2 right?

PHP Code:

$return = "<ul> <li>your mom</li> <li>yodel</li> </ul>";

print $return;

in theory, but I would double check your response. If you're using firefox you can use firebug to check what the request/response actually looked like.

mitechie.com
"Techies just think a little differently
...at least that is what they keep telling me."