[thelist] Access-like drop-downs

VanBuskirk, Patricia pvanbuskirk at otc.fsu.edu
Mon Dec 13 10:20:22 CST 2004


I have a good Javascript that does that...

<!--JavaScript client-side code to alter the default behavior of the onkeypress event-->



<script language="JavaScript" type="text/javascript">
function keySort(dropdownlist,caseSensitive) {
  // check the keypressBuffer attribute is defined on the dropdownlist 
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) { 
    dropdownlist.keypressBuffer = ''; 
  } 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) {
      optionText = optionText.toLowerCase();
    }
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since 
                    // we have selected our own value 
    } 
  } 
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key; 
  return true; // give default behavior 
} 
</script>


<!--Add the functionality to your SELECT tag by calling it in the onkeypress event -->



<select onkeypress="return keySort(this);">
  <option value="Anderson">Anderson</option>
  <option value="Andrews">Andrews</option>
  <option value="Anton">Anton</option>
  <option>etc etc etc</option>
</select>


-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org]On Behalf Of Brooking, John
Sent: Monday, December 13, 2004 11:01 AM
To: thelist at lists.evolt.org
Subject: RE: [thelist] Access-like drop-downs


Ian wrote:
>Does anyone know of a good, easy, way to make HTML drop-down lists
>(<Select>) work like the combo-boxes in Access, whereby, as you type
>letters, the drop-down displays the first entry whose letters match
>those you've typed.

http://www.yCode.com/ has an IE-only solution that is pretty good, if my
memory serves. (I used it once a few years ago, but don't remember many
details.) Don't know how easy or possible it would be to extend to other
browsers.

- John
-- 


This message may contain information which is private, privileged or confidential and is intended solely for the use of the individual or entity named in the message. If you are not the intended recipient of this message, please notify the sender thereof and destroy / delete the message. Neither the sender nor Sappi Limited (including its subsidiaries and associated companies) shall incur any liability resulting directly or indirectly from accessing any of the attached files which may contain a virus or the like.

-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 


More information about the thelist mailing list