IE's Autocomplete and the enter key

BOA_Dev

Active member
Joined
Feb 16, 2007
Messages
32
Programming Experience
1-3
I have a text box and a button and I want the user to be able to use the autocomplete to select a value for the text box using the enter key. The problem is that on the event of the enter key pressed I want to call the button's click event, but what ends up happening is that the button's click event is called before the autocomplete finishes selecting a value.

I want the user to be able to select a value from the autocomplete list using the enter key and then press enter again to call the button's click event.

This is the code Im using to call the button's click event when enter is pressed.

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


So
 
Use onkeyup event instead.

One more note, the controls client-side ID attribute is referenced server-side as ClientID, not UniqueID. UniqueID is the client-side Name attribute. They are not always the same.
 
thanks for the speedy reply. Changing it to onkeyup takes care of the issue but I would prefer it if the user has to press enter twice(one for the autocomplete selection and one for the submit). Is there any way to check if the autocomplete menu has focus? That way I could make it only call the buttons click event when the menu doesnt have focus.

An example of the behavior Im looking for would be google.
 
If you use the onkeypress event the user will first have to press enter for autocomplete choice then enter again to run the javascript handler.
 
Back
Top