|
Question
|
Dictionary type select
How do I setup a dropdown box to have multi-character (dictionary) type select?
If I have Jean, John, and Oscar in the list, I want typing "J" then "O" to go to John, not Oscar.
|
|
Derived from
|
A question posed by archana hari
|
|
Topics
|
JavaScript
|
|
Author
|
Alessandro A. Garbagnati PREMIUM
|
|
Created
|
Aug 17, 2001
|
|
Answer
The behavior of the dropdown box is controlled by the browser and it's not possible to make it "dictionary" type.
Perhaps using an applet or something native (like an ActiveX control) could help.
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|
Comments and alternative answers
 |
ComboSearcher utility
Jeyaram Gurusamy, Sep 19, 2001 [replies:4]
We have an utility which exactly does what you are asking for.
make this as a ComboSearcher.js file and include it in you html/jsp.
check the comments on how to use it.
Its written for IE but only the following 2 lines are specific to IE. You can modify them according to the browser.
window.event.returnValue = false;
var keyCode = window.event.keyCode;
--------------------------------------
/*
* ComboSearcher.js
*
* Usage:
* Just add the following events to your SELECT Tag.
* onfocus="initComboSearch();" onkeydown="searchComboBox(this);"
*
*/
var comboSearchChars;
var KEY_BACKSPACE = 8;
function initComboSearch() {
comboSearchChars = "";
}
function searchComboBox(theComboBox) {
//undo the keypress to avoid the default browser behaviour
window.event.returnValue = false;
var keyCode = window.event.keyCode;
if (keyCode == KEY_BACKSPACE) {
comboSearchChars = comboSearchChars.substring(0, comboSearchChars.length-1);
} else {
var keyChar = String.fromCharCode(keyCode);
comboSearchChars += keyChar.toLowerCase();
}
for (var i = 0; i < theComboBox.length; i++) {
var comboValue = theComboBox.options[i].text.substring(0, comboSearchChars.length);
comboValue = comboValue.toLowerCase();
if (comboValue == comboSearchChars) {
theComboBox.options[i].selected = true;
return;
}
}
}
--------------------------------------
Is this item
helpful? yes no
Previous votes Yes: 4 No: 0
|
|

|
 |
 |
Re: ComboSearcher utility
Andy Withers, Aug 7, 2002 [replies:3]
Jeyaram
I found your script very useful. How do you refresh the search on a field other than refreshing the page
Andy
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
 |
 |
Re[2]: ComboSearcher utility
Jeyaram Gurusamy, Aug 7, 2002 [replies:2]
Hi Andy,
Its very nice to know that my script is useful to you.
Refreshing method 1:
As we are calling initComboSearch() in the onfocus event, the search will be re-initialized each time the field got focus.
Refreshing method 2:
If you want to re-initialize the search without coming out of the field you can press BACKSPACE key which will undo the previous keypress.
Lets say you pressed "a" and then "b". Now you want search for something else. Press BACKSPACE twice. The search will be re-initialized. So you can start searching for something else.
Hope this helps.
Regards
Jai
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
 |
 |
 |
Re[3]: ComboSearcher utility
James Honeycutt, May 8, 2003 [replies:1]
Is there any possible way to have an input field that ties to this drop down so that the user may see what they type?
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
 |
 |
 |
 |
 |
Re[4]: ComboSearcher utility
Anghelescu Dan, Mar 18, 2005
I have some data in my combo that contains "." (dot) and it seems that doesn't work. Is there something that i did wrong?
Thanks
Is this item
helpful? yes no
Previous votes Yes: 0 No: 0
|
|

|
|
|
 |
|