kEk
Awsome script
Definately going in my toolbox
Great job
I would proly give you 500 points for this :>)
Main Topics
Browse All Topics<!-- per request, I am posting this into the public domain. -->
<HTML>
<HEAD>
<!-- 1) Copy-n-paste the code between the SCRIPT tags to a file called "picklist.js" -->
<!-- 2) Include the following in your page: <SCRIPT language="javascript" src="picklist.js" ></SCRIPT> -->
<!-- 3) See the BODY tag, and the comment NOTEs in the form below for setup instructions. -->
<SCRIPT language='javascript'>
//////////////////////////
///// /// Picklist.js -- (C) 1999,2003 by Ralph L. Brown (akakEk) ///// ///
///// /// This script, with copyright notice intact, may be freely ///// ///
///// /// distributed and used for any legal and legitimate ///// ///
///// /// purpose(s) except for the distribution of unsolicited ///// ///
///// /// email (spam) and the publication of pornographic content. ///// ///
//////////////////////////
var UNDEFINED; // do not assign!
function getX(obj)
{
return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.of
}
function getY(obj)
{
return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.off
}
function isvalidchar(achar,validstr
{
if ( !validstr ) validstr = "ABCDEFGHIJKLMNOPQRSTUVWXY
return( validstr.toUpperCase().ind
}
function getQualifiedName(formEleme
{
var formName = formElement.form.name;
if ( formName=="" ) formName=0; // best guess since it is indeterminate for netscape
return 'document.forms["' + formName + '"].elements["' + formElement.name + '"]';
}
function getTooltipDiv()
{
if ( document.getElementById )
return document.getElementById('d
else if ( document.all )
return document.all.divPicklistTo
else return null;
}
function createTooltipDiv(objSel)
{
if ( !getTooltipDiv() ) // if this is the first time this function is
{ // called then create the tooltip text window.
var tooltipDiv = "<DIV id='divPicklistTooltip' style='position:absolute;t
if ( document.body.insertAdjace
{
document.body.insertAdjace
}
else if ( document.body.innerHTML )
{
document.body.innerHTML += tooltipDiv;
}
// necessary for netscape (don`t know why)
setTimeout( "setupPicklist(" + getQualifiedName(objSel) + ")", 1 );
return true;
}
return false;
}
function showTooltipText(objSel)
{
if ( !objSel || objSel.Y==UNDEFINED ) // null or not setup
{
return false;
}
var divPicklistTooltip = getTooltipDiv();
var s = divPicklistTooltip.innerHT
with ( objSel )
{
if ( strKeyInBuf=="" && title.length )
{
s = '<FONT color="blue">' + title + '</font>';
}
else if ( selectedIndex>=0 && strKeyInBuf==options[selec
{
s = '<B>' + strKeyInBuf + '</b>';
}
else
{
var c = strKeyInBuf.substring(strK
c = ( c == ' ' ) ? ' ' : '<B>' + c + '</b>';
s = strKeyInBuf.substring(0,st
}
divPicklistTooltip.innerHT
+ 'font:8pt ms sans serif;padding:2px 2px 2px 2px;color:INFOTEXT;border:
+ '<TR><TD align="left"><NOBR>'+s+'</
divPicklistTooltip.style.p
divPicklistTooltip.style.p
divPicklistTooltip.style.v
} // end with
return true;
}
function hideTooltipText(objSel)
{
if (objSel) objSel.strKeyInBuf = "";
var divPicklistTooltip = getTooltipDiv();
return divPicklistTooltip.innerHT
}
function findSelectEntry( objSel, head, tail ) // uses divide-and-conquer search, assumes sorted list
{
with ( objSel )
{
if ( options.length <= 0 )
{
strKeyInBuf = ' <FONT color="red">No selections available.</font> ';
showTooltipText(objSel);
top.status = strKeyInBuf = "";
return -1;
}
if ( strKeyInBuf == "" )
{
showTooltipText(objSel);
return( selectedIndex = options[selectedIndex=0].t
}
if (head==UNDEFINED) head = 0;
if (tail==UNDEFINED) tail = options.length-1;
var mid = Math.round( (head+tail)/2 );
if ( strKeyInBuf.toUpperCase() == options[mid].text.substrin
{
while ( (mid>0) && strKeyInBuf.toUpperCase() == options[mid-1].text.substr
{
mid--; // get the topmost matching item in the list, not just the first found
}
selectedIndex = mid;
top.status = strKeyInBuf = options[mid].text.substrin
if ( mid == Math.round( (head+tail)/2 ) ) // if the original mid is an exact match
{
if ( (mid==tail) || ( (mid<tail) && strKeyInBuf.toUpperCase() != options[mid+1].text.substr
{
top.status = strKeyInBuf = options[mid].text; // unique match found
}
}
showTooltipText(objSel);
return selectedIndex;
}
if ( head >= tail ) // then since no exact match was found, go back to previous strKeyInBuf (thus the length-1)
{
strKeyInBuf = strKeyInBuf.substring(0,st
return findSelectEntry( objSel );
}
if ( strKeyInBuf.toUpperCase() < options[mid].text.substrin
{
return findSelectEntry( objSel, head, Math.max(head,mid-1) );
}
return findSelectEntry( objSel, Math.min(mid+1,tail), tail );
} // end with
}
function picklistFocusHandler(e)
{
var event = e ? e : window.event; // to handle both NS and IE events
var objSel = event.target ? event.target : event.srcElement;
picklistFocusHandler.objSe
// update data elements
objSel.X = getX(objSel)+2;
objSel.Y = getY(objSel)-20;
objSel.strKeyInBuf = "";
// display the tooltip help (the title attribute by default)
showTooltipText(objSel);
}
function picklistBlurHandler(e)
{
var event = e ? e : window.event; // to handle both NS and IE events
var objSel = event.target ? event.target : event.srcElement;
picklistFocusHandler.objSe
top.status = (objSel.selectedIndex>-1) ? objSel.options[objSel.sele
hideTooltipText(objSel);
return true;
}
function picklistMouseOverHandler(e
{
var event = e ? e : window.event; // to handle both NS and IE events
var objSel = event.target ? event.target : event.srcElement;
showTooltipText(objSel);
return true;
}
function picklistMouseOutHandler(e)
{
var event = e ? e : window.event; // to handle both NS and IE events
var objSel = event.target ? event.target : event.srcElement;
if ( objSel==picklistFocusHandl
return true;
hideTooltipText();
return true;
}
function picklistKeyDownHandler(e)
{
var event = e ? e : window.event; // to handle both NS and IE events
var objSel = event.target ? event.target : event.srcElement;
var divPicklistTooltip = getTooltipDiv();
with ( objSel )
{
// this is to correct the search bug when the list is left open after single-click
if ( strKeyInBuf=="" && event.keyCode>40 )
{
objSel.blur();
objSel.focus();
}
switch(event.keyCode)
{
case(8): // backspace
{
if ( selectedIndex>=0 && strKeyInBuf==options[selec
{
top.status = strKeyInBuf = "";
}
else
{
top.status = strKeyInBuf = strKeyInBuf.substring(0,st
}
selectedIndex = findSelectEntry(objSel);
event.keyCode = 0;
return false;
}
case(9): // tab
case(13): // enter
{
event.keyCode = 9; // convert enter to tab
return true;
}
case(27): // escape
{
top.status = strKeyInBuf = "";
selectedIndex = options[selectedIndex=0].t
showTooltipText(objSel);
event.keyCode = 0;
return false;
}
case(32): // space
{
top.status = strKeyInBuf += ' ';
// this must be fired explicitely for spaces
return !picklistKeyPressHandler(e
}
// I don't know if these are universal
case(33): // page up
case(34): // page down
case(35): // end
case(36): // home
case(37): // left arrow
case(38): // up arrow
case(39): // right arrow
case(40): // down arrow
{
top.status = hideTooltipText(objSel);
return true;
}
} // end switch
} // end with
return true;
}
function picklistKeyPressHandler(e)
{
var event = e ? e : window.event; // to handle both NS and IE events
var objSel = event.target ? event.target : event.srcElement;
var inputChar = String.fromCharCode(event.
if ( inputChar=='\n' || inputChar=='\r' )
{
top.status = objSel.strKeyInBuf = ( objSel.selectedIndex>-1 ? objSel.options[objSel.sele
}
if ( isvalidchar(inputChar) && event.charCode!=0 )
{
objSel.strKeyInBuf += inputChar;
// must use setTimeout to override the default SELECT keypress event(s)
setTimeout( "findSelectEntry(" + getQualifiedName(objSel) + ")", 1 );
}
return true;
}
function setupPicklist(objSel)
{
if ( !document.all && !document.getElementById )
return false; // browser not supported
if ( !objSel || (""+objSel.type).substring
return false; // null or not a select
createTooltipDiv(objSel);
// create/init data elements
objSel.X = getX(objSel)+2;
objSel.Y = getY(objSel)-20;
objSel.strKeyInBuf = "";
// setup event handlers
objSel.onclick = function(){top.status=hide
objSel.onfocus = picklistFocusHandler;
objSel.onblur = picklistBlurHandler;
objSel.onmouseover = picklistMouseOverHandler;
objSel.onmouseout = picklistMouseOutHandler;
objSel.onkeydown = picklistKeyDownHandler;
objSel.onkeypress = picklistKeyPressHandler;
objSel.onkeyup = null;
return true;
}
//////////////////////////
</SCRIPT>
</HEAD>
<BODY onLoad="setupPicklist(docu
<CENTER>
<P align="center"> </P>
<P align="center"> </P>
<P align="center"> </P>
<FORM name="myForm">
<!-- NOTE: The options in the SELECT must be ordered by the .text property! -->
<!-- NOTE: The .value properties can be anything you want. -->
<SELECT name="myPicklist1" size="1" title="Please type your name in the pick-list below." >
<OPTION value="whatever"></OPTION>
<OPTION>Abe</OPTION>
<OPTION>Alice</OPTION>
<OPTION>Alicia</OPTION>
<OPTION>Allen</OPTION>
<OPTION>Arthur</OPTION>
<OPTION>Arty</OPTION>
<OPTION>Beatrice</OPTION>
<OPTION>Ben</OPTION>
<OPTION>Bill</OPTION>
<OPTION>Bing</OPTION>
<OPTION>Brian</OPTION>
<OPTION>Brittany</OPTION>
<OPTION>Bruce</OPTION>
<OPTION>Buzz</OPTION>
<OPTION>Carie</OPTION>
<OPTION>Catherine</OPTION>
<OPTION>Cathy</OPTION>
<OPTION>Charles</OPTION>
<OPTION>Chase</OPTION>
<OPTION>Chris</OPTION>
<OPTION>Christian</OPTION>
<OPTION>Christina</OPTION>
<OPTION>Christopher</OPTIO
<OPTION>Clay</OPTION>
<OPTION>Clayton</OPTION>
<OPTION>Daniel</OPTION>
<OPTION>Danny</OPTION>
<OPTION>Darren</OPTION>
<OPTION>Darryl</OPTION>
<OPTION>Darwin</OPTION>
<OPTION>David</OPTION>
<OPTION>Dean</OPTION>
<OPTION>Derrick</OPTION>
<OPTION>Dinah</OPTION>
<OPTION>Don</OPTION>
<OPTION>Doug</OPTION>
<OPTION>Eathen</OPTION>
<OPTION>Ed</OPTION>
<OPTION>Edward</OPTION>
<OPTION>Edwin</OPTION>
<OPTION>Evan</OPTION>
<OPTION>Forrest</OPTION>
<OPTION>Frank</OPTION>
<OPTION>Fritz</OPTION>
<OPTION>Gary</OPTION>
<OPTION>George</OPTION>
<OPTION>Glenn</OPTION>
<OPTION>Greg</OPTION>
<OPTION>Hank</OPTION>
<OPTION>Hellen</OPTION>
<OPTION>Henry</OPTION>
<OPTION>Imus</OPTION>
<OPTION>Ingred</OPTION>
<OPTION>Jack</OPTION>
<OPTION>Jack Club</OPTION>
<OPTION>Jack Diamond</OPTION>
<OPTION>Jack Heart</OPTION>
<OPTION>Jack Spade</OPTION>
<OPTION>Jackie</OPTION>
<OPTION>Jacob</OPTION>
<OPTION>James</OPTION>
<OPTION>Jason</OPTION>
<OPTION>Jean-Luc</OPTION>
<OPTION>Jerry</OPTION>
<OPTION>Jesus</OPTION>
<OPTION>Jim</OPTION>
<OPTION>John</OPTION>
<OPTION>Katlyn</OPTION>
<OPTION>Kayla</OPTION>
<OPTION>Kendra</OPTION>
<OPTION>Kyle</OPTION>
<OPTION>Lance</OPTION>
<OPTION>Larry</OPTION>
<OPTION>Leah</OPTION>
<OPTION>Lenny</OPTION>
<OPTION>Luke</OPTION>
<OPTION>Mallory</OPTION>
<OPTION>Mandy</OPTION>
<OPTION>Mark</OPTION>
<OPTION>Mary</OPTION>
<OPTION>MaryAnn</OPTION>
<OPTION>Matthew</OPTION>
<OPTION>Michael</OPTION>
<OPTION>Michele</OPTION>
<OPTION>Mickey</OPTION>
<OPTION>Mike</OPTION>
<OPTION>Mitch</OPTION>
<OPTION>Nathan</OPTION>
<OPTION>Ned</OPTION>
<OPTION>Olive</OPTION>
<OPTION>Ollie</OPTION>
<OPTION>Oppie</OPTION>
<OPTION>Pat</OPTION>
<OPTION>Paul</OPTION>
<OPTION>Perry</OPTION>
<OPTION>Peter</OPTION>
<OPTION>Phil</OPTION>
<OPTION>Phillip</OPTION>
<OPTION>Rachael</OPTION>
<OPTION>Ralph</OPTION>
<OPTION>Randall</OPTION>
<OPTION>Randy</OPTION>
<OPTION>Rebekah</OPTION>
<OPTION>Red</OPTION>
<OPTION>Rex</OPTION>
<OPTION>Rick</OPTION>
<OPTION>Ried</OPTION>
<OPTION>Robert</OPTION>
<OPTION>Rodney</OPTION>
<OPTION>Roger</OPTION>
<OPTION>Sally</OPTION>
<OPTION>Sam</OPTION>
<OPTION>Sharon</OPTION>
<OPTION>Sidney</OPTION>
<OPTION>Stephen</OPTION>
<OPTION>Steve</OPTION>
<OPTION>Stuart</OPTION>
<OPTION>Ted</OPTION>
<OPTION>Terry</OPTION>
<OPTION>Theodore</OPTION>
<OPTION>Theresa</OPTION>
<OPTION>Thomas</OPTION>
<OPTION>Tim</OPTION>
<OPTION>Tom</OPTION>
<OPTION>Val</OPTION>
<OPTION>Van</OPTION>
<OPTION>Vince</OPTION>
<OPTION>Wayne</OPTION>
<OPTION>Will</OPTION>
<OPTION>William</OPTION>
<OPTION>Wink</OPTION>
<OPTION>Woody</OPTION>
<OPTION>X</OPTION>
<OPTION>Yoda</OPTION>
<OPTION>Zack</OPTION>
<OPTION>Ziggy</OPTION>
<OPTION>Zurg</OPTION>
</SELECT>
<P><INPUT type="submit" value="Reload" /></P>
</FORM>
</CENTER>
</BODY>
</HTML>
<!------------------------
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I'll just post this for people who needs a smaller script
<HTML>
<HEAD>
<TITLE>Combo Box</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
/* (c) 1999-2003 Michel Plungjan "michel at irt.org"
comments, bugs or improvements welcome */
function checkIt(theValue,theSelect
var theIndex = theSelect.selectedIndex;
if (theIndex ==-1) theIndex = 0;
for (var i=0,n=theSelect.options.le
// if (theSelect.options[i].text
if (theSelect.options[i].text
theSelect.selectedIndex=i;
break;
}
}
}
// uncloak --></SCRIPT>
</HEAD>
<BODY onLoad="document.myform.in
Start typing (case sensitive)
<FORM NAME="myform" onSubmit="return false">
<INPUT NAME="inputField" TYPE="TEXT" SIZE=10 onKeyUp="checkIt(this.valu
<BR><SELECT NAME="List" SIZE="10" onChange="this.form.inputF
<OPTION>A
<OPTION>Apple
<OPTION>Applicable
<OPTION>Application
<OPTION>B
<OPTION>Banana
</SELECT>
</FORM>
</BODY>
</HTML>
/*
more bonus material ...
The .js file below will sort the options in a SELECT, simply do this: qsortSelect(objSelect);
You can use this to sort a SELECT before you initialize it as a PickList.
*/
var UNDEFINED; // do not assign!
function copyOpt( srcOpt, destOpt )
{
if (!srcOpt) return null;
if (!destOpt) return new Option(srcOpt.text,srcOpt.
destOpt.value = srcOpt.value;
destOpt.text = srcOpt.text;
destOpt.selected = srcOpt.selected;
destOpt.defaultSelected = srcOpt.defaultSelected;
return destOpt;
}
function swapOpt( opt1, opt2 )
{
if ( opt1 == opt2 ) return false;
var tmp = copyOpt( opt1 );
copyOpt( opt2, opt1 );
copyOpt( tmp, opt2 );
return true;
}
function qsortSelect( objSelect, head, tail )
{
if (head==UNDEFINED) head = 0;
if (tail==UNDEFINED) tail = objSelect.options.length;
if ( head+1 < tail ) with ( objSelect )
{
var prevlow = head;
for ( var i=head+1; i<tail; ++i )
{
if ( options[i].text.toUpperCas
{
swapOpt( options[i], options[++prevlow] );
}
}
swapOpt( options[head], options[prevlow] );
qsortSelect( objSelect, head, prevlow );
qsortSelect( objSelect, prevlow+1, tail );
}
}
also posted here: http://scriptsearch.intern
Also see: http://phrogz.net/tmp/Type
I just started working on a true HTML combo box. It's pretty limited in it's current implimentation, but I've already started expanding on it. Try it out and let me know if you notice any bugs. I've tested it on Firebird 0.6 and IE 6.0 for the PC
http://www.csb7.com/sample
Business Accounts
Answer for Membership
by: knightEknightPosted on 2003-07-16 at 08:39:03ID: 8935434
also posted on http://www.scriptsearch.co m