I have come up with the follow code which lets the user type in the text box and the select box finds the closest first match. I have a part commented out which will actually highlight the part not typed (just in ie's address bar). It works fine, but when the select boxes get big *500+*(which in my application they are all) it takes a long time.
Is there a better way to do this, or can this be optimized somehow? If you have a better way of doing the same thing or can optimze it please responde
with the new code.
by the way i realize this in an IE only solution and that's ok. I only need it to work in IE.
However I need it to work. Honestly I'd like to just have a select box that worked EXACTLY like the type ahead in IE's address bar.
But I can't figure out how. I don't mind using Active X either. Like i said it only has to work in IE.
Thanks
my code follows:
============
<script language="javascript">
function findMatch(selectBox, txtFind, objEvent) {
if (objEvent.keyCode != 8) {
var i;
var s = "";
var st2 = new String(txtFind.value)
s2 = st2.toLowerCase()
for (i=0; i<selectBox.options.length
; i++) {
s = selectBox.options[i].text;
st = new String(s)
s = st.toLowerCase()
if (s.indexOf(s2) == 0) {
selectBox.selectedIndex = i;
//Selects the text. Commented out because it's too slow.
/*
var typed_string = new String(s2);
var total_string = new String(s);
var t = total_string.length - (total_string.length -
typed_string.length);
var end_string = total_string.substring(t, total_string.length);
txtFind.value = s
if (end_string != "" && end_string.length > 1) {
var range = txtFind.createTextRange();
range.findText(end_string)
range.select();
}
*/
return;
}
}
}
}
</script>
Start Free Trial