Autosuggest which suggests on Enter Key Press

Nighil
Posted by in ASP.NET MVC category on for Beginner level | Points: 250 | Views : 3377 red flag

Normally an Autosuggest control works when we press a key, it will suggest all values.Suppose database has lakhs of records then the problem arise, when user presses key each time it will go to Database and searches this will make Autosuggestion slower so here we will see a Autosuggest which searches when user permit it only by pressing Enter Key


 Download source code for Autosuggest which suggests on Enter Key Press

Introduction

Normally all Autosuggest searches when user types any thing on Autosuggest,here we will look a control
which suggests on enter key press

Objective

Autosuggest control which suggest only on enter key


Using the code

it is really simple to make a control like this, want to make search only when user press enter key
below code will make you clear

if(key==13) return true other wise return false this is the area which makes enter key suggestion

//    $(document).ready(function () {
$("#ItemName").autocomplete({
search: function (event, ui) {
var key = event.keyCode;
if (key == 13) {
return true;
}
else
return false;
},
source: function (request, response) {
$.ajax({
url: '@Url.Action("ItemAutoSuggestByName")',
data: { autoSuggestText: request.term },
dataType: 'json',
type: 'POST',
success: function (data) {
response(data); // You may have to perform post-processing here depending on your data.
}
});
},
select: function (event, ui) {
$('#ItemName').val(ui.item ? ui.item.value : 'Select');
}
});



Conclusion

You can download source and check



Page copy protected against web site content infringement by Copyscape

About the Author

Nighil
Full Name: NIGHIL DAS
Member Level: Starter
Member Status: Member
Member Since: 5/15/2013 5:47:09 AM
Country: India
Nighil Das M


Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)