Im modifying someones code so a little bit lost!
I have a html page with a textbox and button (which performs a search)
Is it possible to perform the search when Enter is pressed on the keyboard?
thanks
P
<div class="col-md-12">
<div id='FAQHome'><h3><a href='newFAQ.aspx'>FAQ HOME</a></h3></div><br><br>
<input id="searchBox" class="searchBox" />
<input id="searchButton" class="searchButton" type="button" value="SEARCH" />
<div id="financialServices" class="mainText"></div>
</div>
<script>
window.document.onkeydown = CheckEnter;
function CheckEnter(){
console.log('CheckEnter' + event.keyCode);
}
$(function(){
$('#searchButton').click(function() {
$('#financialServices').empty();
//do the ajax call ...
$.ajax ({
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('FAQs')/items?$top=100&$orderby=Category,Title asc",
dataType: 'json',
async: false,
headers: { "Accept": "application/json;odata=verbose" },
success: function(data) {
var htmlMain = '';
var tabContent = '';
var theCount=0;
//search
console.log('get search results');
for(var result in data.d.results) {
etc ...
2
Answers
I would suggest that you wrap your input fields in a form element.
…
You can use Keypress Event in jQuery and JQuery keyCode.
jQuery keypress Event reference : https://api.jquery.com/keypress/
jQuery key code reference : https://www.educba.com/jquery-keycode/
Use Like:
Full code :