/    Sign up×
Community /Pin to ProfileBookmark

HELP NEEDED – Select list autocomplete

Hello all, I am new to this forum, not so new to JavaScript. But I do need some help. I have a select form element structured like this:

[CODE]
<select name=”buyer_id”>
<option value=”1″>John Adams</option>
<option value=”2″>Bill Amos</option>
<option value=”3″>Fred Boon</option>

</select>
[/CODE]

The name list is now getting huge and I would like to allow my admins to be able to type in the first few letters of a buyers name and have the select form “find” what the admin is entering. But I need the value of the buyer to be passed as the buyer’s id for DB purposes. Can someone explain how this might be done or point me toward some tutorials/examples? All help is greatly appreciated.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@NedalsMar 11.2005 — If you list and order the names 'lastname, firstname', <select> will find a match to the first letter of the name by default, which will get you close.

To do what you want with javascript, you will need a text field to enter the name. Javascript could set the <select> as you enter the letters.
Copy linkTweet thisAlerts:
@everahauthorMar 11.2005 — Thanks Nedals. I found a script that actually does what I want using a <select> field, but there is one little annoyance with it. Whenever a letter key is pressed, the <select> finds the first occurrence of the letter (as usual with a <select> field). It does come back immediately, but it doesn't look good when you are typing through the options and it keeps flashing from one to the other.

For an example you can visit [URL=http://www.purelyauto.com/ac_test_4.html]http://www.purelyauto.com/ac_test_4.html[/URL]. Full source is available from VIEW -> SOURCE when at the page.

This script does exactly what I want it to do except for that blinking action. Any ideas?
Copy linkTweet thisAlerts:
@Warren86Mar 11.2005 — .
Copy linkTweet thisAlerts:
@everahauthorMar 11.2005 — Thanks for the post Warren86. It looks like your solution uses a text box to populate a <select> item. I need to be able to do the autocomplete in the <select> item itself so as to be able to pass the id value associated with the option shown. Ex:
[CODE]
<select name="buyer_id">
<option value="1">John Adams</option>
<option value="2">Bill Amos</option>
<option value="3">Fred Boon</option>
...
</select>
[/CODE]

I need to be able to type the option text but capture the option ID for insertion into the DB. So in the example, when John Adams is finally chosen as the selected option, I need to be able to pass "1" through the form into the database. Make any sense?
Copy linkTweet thisAlerts:
@Warren86Mar 11.2005 — No. Makes no sense.

That's what my code did. But, all you did was LOOK at it and decide that it's no good.

I deleted my code.

Nothing that anyone could possibly post would suit you.

I won't trouble you again.
Copy linkTweet thisAlerts:
@everahauthorMar 12.2005 — Sorry if I offended you. You're right, I did LOOK at the code. I noticed the textbox field and the select field. I didn't have a chance to try it out yet and assumed that it used two fields. My mistake.

I am very grateful for your help and all the help that I get on all the forums I visit. I know your time is valuable as is the product you develop. I am sorry if I minimized that to you.

Again, I apologize if I offended you. It was not my intent.
Copy linkTweet thisAlerts:
@Warren86Mar 12.2005 — Find someone else to try and manipulate.
Copy linkTweet thisAlerts:
@everahauthorMar 12.2005 — Very well. Happy coding. I am certain someone will be helped by you. For what it's worth, don't you think that the code you posted might be valuable to someone somewhere? What I mean is, just because I made you upset doesn't mean that others wouldn't still benefit from your knowledge.
Copy linkTweet thisAlerts:
@everahauthorMar 12.2005 — Thank you. This is exactly what I am looking for. Everything works perfectly in your script. Thanks for the script.
Copy linkTweet thisAlerts:
@everahauthorMar 23.2005 — A1ien51, would you know of a way to couple your autoselect feature with a "select and go" type feature? I tried this but for some reason when I tab out of the select box I get a JavaScript error about an index not being an object. Any suggestions?
Copy linkTweet thisAlerts:
@A1ien51Mar 23.2005 — There is a disussion on this script [URL=http://www.codingforums.com/showthread.php?t=9865]here[/URL]. You may be able to get an answer there.

Eric
×

Success!

Help @everah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...