Search code examples
c#javascriptjqueryasp.netajaxcontroltoolkit

Auto Complete Textbox Enter to activate Search


I have a Ajax auto complete extender attached to TextBox control. When the user starts typing the suggestive options are displayed in the divsion underneath. Getting the suggestion from a webservice call. On OnClientItemSelected="GetCode" I am using the below JavaScript to get the selected suggestion text into the search box.

Now I want the ENTER click to activate the search.

If the user selects from the suggestions he is getting and clicks the enter. It works fine. It activates the search. This is the code I am using.

function GetCode(source, eventArgs) {

    var txtValue = document.getElementById('<%=txtAutoComplete.ClientID%>');
    txtValue.value = eventArgs._value;
    //$('#<%= txtAutoComplete.ClientID %>').val(eventArgs._value);
    $('#<%= ImageButton1.ClientID %>').click();
}

But The problem is if the user doesnt select from the suggestion and types some text and clicks the enter key Doesnot activate search. Yes I know that It doesnot call the GetCode Function.

I am not getting how to do this. Anyone Please help me..

I am want something exactly like in www.laterooms.co.uk


Solution

  • You have to set a default button for either the form or the text field.