Dynamically search in the options of a dropdown
<input id="fastFind" type="text" autocomplete="off" onkeyup="gosearch(event, 'fastFind', 'mainvalues')" name="fastFind">
<select id="mainvalues" name="mainvalues" size="10">
<option value="1">Test</option>
</select>
<script>
function gosearch(e, name, value) {
if (e.keyCode != 9 && e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) {
var source = document.getElementById(value);
var textInput = document.getElementById(name).value;
if (textInput.length > 0 ) {
for (var i = 0; i <= source.length-1; i++) {
var sText = source[i].text.toLowerCase();
var sString = textInput.toLowerCase();
if (sText.match(sString)) {
source[i].selected = true;
break;
}
}
} else {
source.selectedIndex = -1;
}
}
}
</script>