I have a textbox for search items. I want to get items when type text in textbox and press enter key.
<input id="txt-search" placeholder="@StoreResource.SearchHere" class="form-control main-in">
<a href="javascript:void(0);" id="btn-search" class="search-icon">
<i class="icon feather icon-search"></i>
</a>
I use this code but get empty value.
$("#txt-search").keyup(function (e) {
var txt = $(this).val();
if (e.key == "Enter") {
alert(txt);
}
})
2
Answers
It is working as expected.
One verify in below link stackbltiz
If it is not expected , comment your requirement clearly.
This code works as expected. When entering the value into the text box and press enter then get the value which is entered into the textbox.