Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I program a dropdown so it would change the value

Status
Not open for further replies.

Ankor

Programmer
Mar 21, 2002
144
US
I am looking for the code that would change the dropdown value while the user is typing what he needs. The usual dropdown will accept only the first character, but I have a long list of options where the first character is the same, so I'd like to be able to type two or three characters, and the dropdown should change accordingly. Is there a way to do it?
 
Thanks, but it's not quite what I need. I have a prepopulated dropdown menu, and the users should be able to use it as a regular dropdown menu - without typing. I would not want to convert it to the text box as not everyone knows what options are available and may want to scroll through all elements.
 
this is what you said in your original posting...

I am looking for the code that would change the dropdown value while the user is [red]typing what he needs[/red]

and in the second post you said...

use it as a regular dropdown menu - [red]without typing[/red]

Please aake sure what you want to do and then ask a specific question to get correct responses.

-DNG
 
Both are correct.

I have a dropdown where the user should be able to pick the value without typing.

At the same time, if the user selects the dropdown and starts typing, the selected item should change. The same way how it works by default for the first character, but I want to be able to type two or three characters.
 
Well, there is one method I have used recently and two I have not.
The easiest method is to put a search text box right next to your dropdown and use the OnKeyDown event to advance the select box to the closest match. This takes up more real estate and is a little moe complicated for the end user, but fairly easy to implement.
The next method would be to use a hidden input and use the onKeyDown event of the dropdown to pass the key code to the hidden input. Then using a function similar to the above you would search the select for the nearest match. In this case you would want to return false and setup the onKeyDown to = "return DoKeyDownFunc()" so that the key press was not passed to the select box. Basically this should override it's normal action. This is a bit closer, but you don't have the visible text that is being typed for a search and it's less obvious. You would probably also want to write an OnChange for the select to clear the hidden box you were searching with.
The most complcated method (unless you find a 3rd party object) is to basically create your own dropdown list with a text input, button, and scrollable div or ul. The div holds the list of items and you would need several javascript functions to handle displaying, hiding, searching, selecting, highlighting, etc.

All in all, thee are client-side solutions and you might have better luck trying either the HTML or javascript forums.

-T

 
Tarwn, thank you. I have already tried using a text box with the drop-down box, but my client did not like it. I guess I found the code for your second solution: It will have to be customized a little bit, but it has potential :).
Thanks again for your help.
 
No problem. I didn't have time for a detailed set of examples, so I was hoping that by outlining some options you would either find a tutorial/example or someone esle would post one :)

Either way, glad you found a link (and posted it for us).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top