I am using javascript to make a dropdownlist act like a combobox and it is work well. The issue I'm having is when the user types in the combobox and finds the selection he wants, he has to use the mouse to make the actual selection. The user wants to have the option of just hitting the enter key instead of using the mouse. He also wants to use the tab key to move to the next field. I'm using onkeydown to call the javascript, and I know I need to check for key code == 13 (for the enter key), but then what? How do I translate it into a select? I tried using document.getElementById("<%=Director.ClientID%>"). click(); but the combobox just hung. Please help, someone.
<script language="javascript">
var searchID;
var searchValue;
function checkKey(oList, e) {
// Re-initialize if the
if(oList.id != searchID) {
searchID = oList.id;
searchValue = "";
}
var theKey;
var binIE;
// check for browser event model
if(window.event) { theKey = window.event.keyCode; binIE = true; }
else { theKey = e.which; binIE = false; }
if(theKey == 8) { // check for backspace
searchValue = ""; // clear the filter
}
else if(theKey == 13) { // check for enter
return;
}
// check for alphanumeric keys and append to the search value
else if((theKey >= 48 && theKey <= 57) || (theKey >= 65 && theKey <= 90) ||
(theKey == 32) || (theKey >= 96 && theKey <= 105)) {
searchValue += String.fromCharCode(theKey).toLowerCase();
}
else { return false; }
// loop through the list to select the proper item
if(searchValue != "") {
for(var iCheck=0;iCheck<oList.options.length;iCheck++) {
if(oList.options[iCheck].text.toLowerCase().indexOf(searchValue) == 0) {
oList.options[iCheck].selected = true;
return;
}
}
}
}
</script>
<td align="left" width="25%">
<asp:DropDownList id="Director" onkeydown="checkKey(this, event);return false;" runat="server"></asp:DropDownList>
</td>