Example: Combobox (Or list) Autocomplete - as you type
Took a while to find it, so i wanted to post it and I bet someone has lots of ideas on how make it faster, better, etc....
Input_ItemInfo_Units.setEvent("onkeyup", function(event){
var key=String.fromCharCode(event.keyCode || event.charCode);
switch (event.keyCode) {
case 38:case 40:case 37:case 39:
case 33:case 34:case 36:case 35:
case 13:case 9:case 27:case 16:
case 17:case 18:case 20:case 8:
case 46:
return;
break;
};
var tbox = this.getContent("box/text").element();
var tboxValue=tbox.value;
var i;
var found=false;
for(i=0;i<this.getItemCount();i++){
if(this.getItemText(i).toUpperCase().indexOf(
tboxValue.toUpperCase()) == 0){
found=true;
break;
}
}
var sText = event.charCode;
var iStart = tbox.selectionStart;
tbox.setSelectionRange(iStart+sText.length, iStart+sText.length);
var iLen = tbox.value.length;
if(found){
tbox.value = this.getItemText(i);
this.setCurrentItem(i);
}else{
tbox.value = '';
}
tbox.setSelectionRange(iLen, tbox.value.length);
return;
});
John Mason
December 6,