I created a search form and I set a function which tells the browser to display a JSON file whenever a string is entered on the text field and the button Search
is pressed:
$("#IDofTheSearchButton").on('click', function);
I want to call the same function also whenever the input field is filled up and the user presses the Button Enter
on the keyboard.
How can I do that?
- E D I T [ S O L V E D ]- - - -
I edit the code as in the following, by exploiting the keydown
event listener, and it works now:
$('#IDofTheInputField').on('keydown', function(e) {
if (e.which == 13) {
e.preventDefault();
nameOfTheFunction();
}
} );
I also added the preventDefault()
method to prevent the Enter
key to activate the Submit
event (otherwise, the code doesn't work for this specific key).