473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How do I make the enter key select a combobox value?

1
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>
Feb 14 '08 #1
1 2161
=======================Check in javascript=========
function captureEnterKey()
{
if(event.keyCode == 13)
{
// alert('keycode= ' + event.keyCode);
var a= document.getElementById("ctl00_ContentPlaceHolder1 _UserControlPanel1_btnGo")
a.focus();
}
}
=============================================


==================Code Behind=======================
txtProductName.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) ||(event.keyCode == 13)){document.getElementById('" + btnGo.UniqueID + "').click();returnfalse;}} else {return true}; ")

ddlCategoryName.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) ||(event.keyCode == 13)){document.getElementById('" + btnGo.UniqueID + "').click();returnfalse;}} else {return true}; ")

ddlSubcategoryName.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) ||(event.keyCode == 13)){document.getElementById('" + btnGo.UniqueID + "').click();returnfalse;}} else {return true}; ")

here ddlcategoryname & ddlsubcategory name is drop down list

====================================
Feb 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Programatix | last post by:
Hi, I'm having problem with ComboBox. I'm trying to force the ComboBox select nothing by doing this, myCombo.SelectedText = "" myCombo.SelectedIndex = -1 but in vain, as the ComboBox will...
2
by: SAN CAZIANO | last post by:
check required in a select how can i control if a combobox (a select) is not null (index is -1) or if index is 0 if the first element is for example a null value or simply a description of the...
3
by: RR | last post by:
What would the proper way be to enter a sale, then be able to enter 1 or more sales persons, their "costs" to the sale, and their commission on the sale? Then after its been entered, have all the...
8
by: ShyGuy | last post by:
Is it possible to use code to enter some text into a combo box and then have the cursor placed at the end of the text for more imput?
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
1
by: billypit | last post by:
Hi, I am totaly new to MS Access. I have one form in MS Access in which i want that whenever i select an item from combobox then in the textbox on the same form or subform i want value from table...
3
by: BASSPU03 | last post by:
I had to present my DB today, but was granted a chance to fix something about it. In order to fix something, I added something...something that is giving me more trouble than it should. I have to...
1
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound...
7
by: creative1 | last post by:
hi, I have a simple query. I have a dynamic combobox when I select one value fromt he combobox; on click a function is called that display the value of the combobox(i.e not same as text list of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.