Click here to Skip to main content
14,878,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

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

Thanks
Posted
Updated 3-Aug-11 1:33am
v2

1 solution

Put the text box in a <form> with the action as the search (or, if you're doing clever AJAX tricks, with the action as a javascript function that starts the search). Enter automatically submits HTML forms when pressed in any text input control within the form.

You could also make it work with a client-side onKeyPress. But putting it in a <form> makes semantic sense and is easier (and degrades better if your user has JS turned off), so I'd definitely do that unless there is some reason you can't.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900