Here is a text field and button which call a search function when it is clicked.
But, at times we need to use normal buttons that do not function like submit buttons, for instance, or we cannot fire a function when a particular key is pressed. We have to explicitly call a function on the onclick event of the button.
However, we can work around to make the normal button to intercept the key-stroke, read it and call the function if the key code corresponds to the key “Enter”.
The above code demonstrate how to call a function when the user presses the enter key but you can specify which key you want attached to the event and replace the key code above with the ASCII value of the new key.