Auto-Populate Selection List on Search

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Auto-Populate Selection List on Search

Post by Skara »

The Problem:
I have a long list of clients. I need to attach a main contact to each project (in a longer list of projects).

The Idea:
I need a scrolling select field that, at first, displays the most recent clients added (say 5). But when you start typing in the search box, it populates as you type with possible matches. You click on the person you want, click [Attach], and you're done.

Search Clients: [__start_typing_client_name_here__]
Select Client:
[______]
[______]
[______]
[______]
[Attach]

I'm thinking this is probably pretty easy; I'm just terrible when it comes to anything client-side. Can someone point me in the right direction?

Bonus Thought:
If I could figure out how to have the list auto-populate with more entries as you scrolled down through them, that would be awesome—particularly while it's still displaying the most recent clients.


Thanks!
—(totally lost) William
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Auto-Populate Selection List on Search

Post by Christopher »

This would be done with javascript. Are you using a javascript library?
(#10850)
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Auto-Populate Selection List on Search

Post by Skara »

I'm using jQuery for a couple of other things. I understand the syntax, I just need to know what to do with it. Hah.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Auto-Populate Selection List on Search

Post by Christopher »

You can use jQuery's .html() method to set the options in the select. The search box would make an Ajax call each time a character is typed. The Ajax call would call a PHP script that generates the <option> list base on the search string.

Or if the list is not too long, you could do the whole thing in javascript. When you generate the page you would create a javascript array of the full client list -- and then search for matches in it to create the <option> list.
(#10850)
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Auto-Populate Selection List on Search

Post by Skara »

GOT it. Problem solved.

Thanks.
Post Reply