Check out the demo (http://jquery.bassistance.de/autocomplete/demo/),
pick the example that comes closest to your requirement, and take a
look at the code for that one. Firebug helps a lot there.

>From what you describe, the "single bird (remote)" comes quite close.
This is the code for it:

$("#singleBirdRemote").autocomplete("search.php", {
                width: 260,
                selectFirst: false
        });
$("#singleBirdRemote").result(function(event, data, formatted) {
                if (data)
                        $(this).parent().next().find("input").val(data[1]);
        });

The resource search.php gets a paramter q with the entered term and
returns a list of terms, columns separated with a pipe, rows with
newline (again, Firebug helps, just look at the request/response).
The second part puts the id, via data[1], into the input field on the
next line. You'd most likely make that a hidden field, reference it by
id or class and give it a name to handle it on the serverside.

In general I can recommend to learn some jQuery basics, that will get
you a long way.

Jörn

On Tue, Jul 15, 2008 at 7:49 PM, fredriley <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> I'm new to jQuery and to this list. This is a question I sent to
> another web developer's list yesterday, after spending many hours
> trying and failing to get the Autocomplete (http://docs.jquery.com/
> Plugins/Autocomplete) jQuery plugin to do what I wanted:
>
> ~~~~~~~~~
> Ok, I give in - I've been staring at a screen for 5 hours now trying
> to find a good autocomplete function/plugin/module/wossname for a
> database entry form. A decent candidate is the jQuery Autocomplete
> plugin which I've sort of got working on a test doc (http://
> www.nottingham.ac.uk/~ntzfr/test/ajax/jquery/jquery_test1.html).
> What I'd like to do is autosuggest for keywords pulled from a mySQL
> table as id|title ('select id, title from keywords order by title' or
> somesuch). So the autocomplete shoves title into the input field, but
> I can't figure out, because my brain's gone dead, how to get the id.
> Store it in a hidden field, perhaps, but how to do that using this
> component and/or jQuery?
>
> If anyone's using this component my hurting brain would be grateful
> for a tip :(
> ~~~~~~~~~
>
> Maybe the result() handler might do the job, but in order to
> understand how that works I'd have to understand jQuery properly,
> which would take another good few hours on top of the few I've spent
> on it already, all for a user interface 'grace note', and I don't have
> that sort of time. The author of this plugin suggested posting
> problems to this board with [autocomplete] in the subject, so here we
> go.
>
> There are other autocomplete Ajax scripts but all have their problems,
> mostly due to reliance on Ajax frameworks I know little of and don't
> have the time to learn (MooTools, Ruby on Rails, script.aculo.us,
> Sajax, and many more), sometimes due to requiring data output from a
> PHP script in XML and/or JSON which would be a step too far. I think I
> understand basic Ajax, at least the XHR bit (test at
> http://www.nottingham.ac.uk/~ntzfr/test/ajax/), and can get data from
> PHP, it's the drop-down eye-candy that defeats me. My past experience
> with JS/DOM is that it can take hours, days to implement the simplest
> things, hence my turning to jQuery to try to speed up development and
> reduce headaches, without much success so far.
>
> Any suggestions? All would be gratefully received and picked over. If
> not I'll knock it on the head and the user can do their own damn
> typing ;-(
>
> Cheers
>
> Fred
>

Reply via email to